My favorite explanation remains the one I came up with at http://www.mail-archive.com/boston-pm@mail.pm.org/msg02716.h....
sub {
my $builder = shift;
return sub {
my $n = shift;
return $builder->($builder)->($n);
};
}->(
sub {
my $recurse = shift;
return sub {
my $n = shift;
say "$n"; # Just a way to test
if (0 == $n) {
return 1;
}
else {
return $n * $recurse->($recurse)->($n - 1);
}
};
}
)->(5);
I was confused about the "perl can't do this" part.But when you drop the pretenses, you're still doing assignment. (Though otherwise you've perfectly duplicated the pattern.)
use strict; use warnings; use signatures;
sub ( $builder ) {
return sub ( $n ) {
return $builder->($builder)->($n);
};
}->(
sub ( $recurse ) {
return sub ( $n ) {
if (0 == $n) {
return 1;
} else {
return $n * $recurse->($recurse)->($n - 1);
}
};
}
)->(5);I still think that my email was accurate as of 2005.
http://stackoverflow.com/questions/93526/what-is-a-y-combina...