Created
August 22, 2012 20:55
-
-
Save belden/3429266 to your computer and use it in GitHub Desktop.
y-combinator.pl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
sub y_combinator (&) { | |
my $curried = shift; | |
return sub { | |
my $f1 = shift; | |
return $curried->(sub { $f1->($f1)(@_) }); | |
}->(sub { | |
my $f2 = shift; | |
return $curried->(sub { $f2->($f2)(@_) }); | |
}); | |
} | |
my @numbers = (1,2,3); | |
y_combinator { | |
my $recurse = shift; | |
return sub { | |
my $number = shift @numbers; | |
warn "number: $number\n"; | |
return scalar @numbers ? $recurse->() : undef; | |
}; | |
}->(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My big references for y-combinators are:
http://stackoverflow.com/questions/93526/what-is-a-y-combinator
and two of the linked articles:
http://mvanier.livejournal.com/2897.html
http://www.mail-archive.com/[email protected]/msg02716.html