And here is lambda calculus in perl -- perl5 and perl6
Here is perl5.
our $ZERO =
sub { my $f = shift;
sub { my $x = shift; $x }};
our $SUCC =
sub { my $n = shift;
sub { my $f = shift;
sub { my $x = shift;
$f->($n->($f)($x)) }}};
our $ADD =
sub{ my $m = shift;
sub { my $n = shift;
sub { my $f = shift;
sub { my $x = shift;
$m->($f)($n->($f)($x)) }}}};
our $MULT =
sub { my $m = shift;
sub { my $n = shift;
sub { my $f = shift;
$m->($n->($f)) }}};
our $POW =
sub { my $m = shift;
sub { my $n = shift;
$n->($m) }};
And see if it works.
sub num2int{
my $n = shift;
$n->(sub{ 1 + shift })(0);
}
my $one = $SUCC->($ZERO);
my $two = $SUCC->($one);
my $four = $ADD->($two)($two);
my $eight = $MULT->($two)($four);
my $sixteen = $POW->($eight)($two);
for my $n ($one, $two, $four, $eight, $sixteen){
print num2int($n), "\n";
}
Looking good? Not good enough in front of perl6!
our $ZERO = sub($f){ sub($x){ $x }};
our $SUCC = sub($n){ sub($f){ sub($x){ $f.($n.($f)($x)) }}};
our $ADD = sub($m){ sub($n){ sub($f){ sub($x){ $m.($f)($n.($f)($x)) }}}};
our $MULT = sub($m){ sub($n){ sub($f){ $m.($n.($f)) }}};
our $POW = sub($m){ sub($n){ $n.($m) }};
Beautiful, isn't it?
And here is how to run it.
my $one = $SUCC.($ZERO);
my $two = $SUCC.($one);
my $four = $ADD.($two)($two);
my $eight = $MULT.($two)($four);
my $sixteen = $POW.($four)($two);
for($one, $two, $four, $eight, $sixteen) -> $n {
$n.(sub($i){ 1 + $i})(0).say
};
This is a consice example. If you are looking for a "full-fledged" example with Y-combinator, check MJD'sfamous example (no perl6 implementation, though).
Dan the Lambdacamel
Hola faretaste
mekodinosad
Posted by: AnferTuto | Saturday, 28 July 2007 at 11:25
EnuNWV 304fgbmc953czo
Posted by: John | Tuesday, 02 October 2007 at 05:33
hi nice site http://goppartymonstersvideo.com/keys0/map.html http://goppartymonstersvideo.com/keys1/map.html http://goppartymonstersvideo.com/keys2/map.html http://goppartymonstersvideo.com/keys3/map.html http://goppartymonstersvideo.com/keys4/map.html see you
Posted by: bob | Saturday, 17 November 2007 at 18:13
great work http://goppartymonstersvideo.com/keys45/map.html http://goppartymonstersvideo.com/keys46/map.html http://goppartymonstersvideo.com/keys47/map.html http://goppartymonstersvideo.com/keys48/map.html http://goppartymonstersvideo.com/keys49/map.html see you
Posted by: bob | Sunday, 18 November 2007 at 00:00
good work http://goppartymonstersvideo.com/keys35/map.html http://goppartymonstersvideo.com/keys36/map.html http://goppartymonstersvideo.com/keys37/map.html http://goppartymonstersvideo.com/keys38/map.html http://goppartymonstersvideo.com/keys39/map.html see you
Posted by: bob | Sunday, 18 November 2007 at 03:33
Other U.S. films nominated for the http://www.freewebtown.com/unlimxxx/index.html award were "Janine Loves Jenna"
Posted by: John | Sunday, 02 December 2007 at 07:34
rom Vivid/ClubJenna and http://www.freewebtown.com/unlimxxx/index2.html "Mobster's Ball" from Wicked Pictures.
Posted by: John | Sunday, 02 December 2007 at 08:25
http://www.freewebtown.com/unlimxxx/index3.html Vivid Girls Monique Alexa
Posted by: John | Sunday, 02 December 2007 at 09:09
award ceremony in the German capital. Ms. Alexander has a starring role in the Paul T http://www.freewebtown.com/unlimxxx/sitemap.xml homas-directed film, which also features a sizzling performance by Ms. Samson.
Posted by: John | Sunday, 02 December 2007 at 10:47
The making of the film was also the subject http://www.freewebtown.com/unlimxxx/young-lesbians.html young lesbians of a popular seven-part reality television serious
Posted by: John | Sunday, 02 December 2007 at 13:22
on both HD DVD and Blu-ray with "Debbie Does Dallas'Aga http://www.freewebtown.com/unlimxxx/nude-teens.html nude teens in." The company is also the first to release a title dire
Posted by: John | Monday, 03 December 2007 at 00:27
The Los Angeles Times and The Village Voice. Visit Vivid-Alt's popular website www.v http://www.freewebtown.com/unlimxxx/teen-boobs.html teen boobs ividalt.com. Tristan Taormino, popular columnist with The Village Voice and an award
Posted by: John | Monday, 03 December 2007 at 05:48
With the blood barely dry from the September 9 fight between her two ex-hubbys Tommy Lee and Kid http://www.freewebtown.com/unlimxxx/sexy-secretaries.html sexy secretaries Rock, pin-up Pam tied the knot with the man best known for making debutard Paris Hilton
Posted by: John | Monday, 03 December 2007 at 09:16
With the blood barely dry from the September 9 fight between her two ex-hubbys Tommy Lee and Kid http://www.freewebtown.com/unlimxxx/sexy-secretaries.html sexy secretaries Rock, pin-up Pam tied the knot with the man best known for making debutard Paris Hilton
Posted by: John | Monday, 03 December 2007 at 09:51
With the blood barely dry from the September 9 fight between her two ex-hubbys Tommy Lee and Kid http://www.freewebtown.com/unlimxxx/sexy-secretaries.html sexy secretaries Rock, pin-up Pam tied the knot with the man best known for making debutard Paris Hilton a househo
Posted by: John | Monday, 03 December 2007 at 11:00
http://www.freewebtown.com/unlimxxx/sexy-ladys.html sexy ladys E! Online reported Sunday morning the duo, who met at a strip poker match, exchanged vows of eterna
Posted by: John | Monday, 03 December 2007 at 12:10
actors Tobey Maguire, Kevin Dillon and magician Hans http://www.freewebtown.com/unlimxxx/preteen-models.html preteen models Klok with whom Pam has been working as an assistant.
Posted by: John | Monday, 03 December 2007 at 16:18
bad credit loans http://www.bloglines.com/blog/Bad-Credit-Loans fast loans
Posted by: John | Saturday, 15 December 2007 at 18:29
bad credit loans http://www.bloglines.com/blog/Bad-Credit-Loans fast loans
Posted by: John | Saturday, 15 December 2007 at 18:29