Currying in Perl 6

| No Comments | No TrackBacks

There is still quite a lot of low-hanging fruit in Rakudo.

I checked on IRC today during a break in the class I'm teaching to see jhorwitz asking for currying in Perl 6, which is spelled like:

my $curried = &function.assuming(...);

A few minutes later, I committed an implementation of it. Here is the currying patch for Rakudo. It's about the same size as the last patch I mentioned here. Here are the tests we're now passing:

sub tester(:$a, :$b, :$c) {
"a$a b$b c$c";
}

my $u = &tester.assuming(b => 'x');
is $u(a => 'w', c => 'y'), 'aw bx cy', 'currying one named param';

my $w = &tester.assuming(b => 'b');
my $v = $w.assuming(c => 'c');
is $v(a => 'x'), 'ax bb cc', 'can curry on an already curried sub';
is $w(a => 'x', c => 'd'), 'ax bb cd', '... and the old one still works';

No TrackBacks

TrackBack URL: http://blogs.gurulabs.com/cgi-bin/mt-tb.cgi/103

Leave a comment

About this Entry

This page contains a single entry by Stephen Weeks published on December 11, 2008 8:25 PM.

Exception Handlers in HLLs was the previous entry in this blog.

Non-fatal exceptions is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Pages

OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.25