Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Specializing Functions with Currying

by kabel (Chaplain)
on Aug 06, 2004 at 05:48 UTC ( #380452=note: print w/ replies, xml ) Need Help??


in reply to Specializing Functions with Currying

i do not know if this is useful for anything, but

sub curry2 { my ($fn, $argstack) = @_; defined $argstack or $argstack = []; return sub { my $arg = shift; if (defined $arg) { return curry2 ($fn, [@$argstack, $arg]); } else { $fn->(@$argstack); } }; }
transforms a function f into a function which can be positionally parametrised, though named would pose too no problems. sample usage:
my $myprint = sub { print @_; }; my $curry = curry2 ($myprint); $curry->("a")->("b")->("c")->();


Comment on Re: Specializing Functions with Currying
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-11-29 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (203 votes), past polls