Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^4: Near-free function currying in Perl

by stvn (Monsignor)
on Nov 17, 2004 at 15:45 UTC ( #408445=note: print w/replies, xml ) Need Help??


in reply to Re^3: Near-free function currying in Perl
in thread Near-free function currying in Perl

My experience with function attributes is limited but what about something like this:

sub foo ($$$) : curry { ... }
or if the prototypes and attributes dont get along as they should.
sub foo : curry($$$) { ... }
That would be my prefered notation, it is was possible.

-stvn

Replies are listed 'Best First'.
Re^5: Near-free function currying in Perl
by dragonchild (Archbishop) on Nov 17, 2004 at 16:20 UTC
    I like
    sub foo : required($$$) { ... }

    That allows more than just currying to use the attribute. Also, you can then do something like:

    sub foo : required( address, city, state, zip ) { ... }

    That way, you can do both parameter validation and named-parameter currying (as per Limbic~Region's comment below). Plus, you're specifying the API, which would allow for something like doxygen to document your API.

    An even nicer thing would be to combine this idea of a required() attribute to methods, meaning that you could do something like:

    package Foo; sub new : required( attr1, attr2 ) : optional( attr3 ) { ... }

    This would behave like Class::MethodMaker and create the attr1(), attr2(), and attr3() mutators, plus require that the first two be passed in to the constructor.

    It wouldn't be too hard to come up with a list of useful function/method attributes. Off the top of my head, I can see multiple uses for:

    • required
    • optional
    • deprecated

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re^5: Near-free function currying in Perl
by stvn (Monsignor) on Nov 17, 2004 at 16:40 UTC
      Maybe we can expand it to work with optional parameters and named parameters ... *ponders* It's very similar to what I posted below. Hrmm ... maybe we can come up with a spec that would meet everyone's needs?

      Being right, does not endow the right to be rude; politeness costs nothing.
      Being unknowing, is not the same as being stupid.
      Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
      Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://408445]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2020-11-24 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?