3 ms·
My favorite explanation remains the one I came up with at http://www.mail-archive.com/boston-pm@mail.pm.org/msg02716.html http://www.mail-archive.com/boston-pm@
by btilly 15y ago
My favorite explanation remains the one I came up with at http://www.mail-archive.com/boston-pm@mail.pm.org/msg02716.html http://www.mail-archive.com/boston-pm@mail.pm.org/msg02716.h....
- dionidium 15y agoYou should definitely add that as an answer on SO. The current answers are not very useful.
- btilly 15y agoAdded at http://stackoverflow.com/questions/93526/what-is-a-y-combinator/6713431#6713431 http://stackoverflow.com/questions/93526/what-is-a-y-combina...
- dionidium 15y agoI just worked through this for myself. Maybe someone will find another approach useful: http://stackoverflow.com/questions/93526/what-is-a-y-combinator/6714066#6714066 http://stackoverflow.com/questions/93526/what-is-a-y-combina...
- Xurinos 15y agoLet's just pretend we are binding values. There are ways to make perl look like you are doing parameter assignment. 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.
- btilly 15y agoPretending you are binding values instead of assignment means you can pretend to achieve the goal in Perl. But when you drop the pretenses, you're still doing assignment. (Though otherwise you've perfectly duplicated the pattern.)
- peteretep 15y agoI say I say I say... 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);
- btilly 15y agoCute. But I wrote the email under discussion in 2005, and the first version of signatures was not released until 2008. I still think that my email was accurate as of 2005.
- draegtun 15y agoAristotle also does a great explanation in this use.perl.org post: http://use.perl.org/~Aristotle/journal/30896 http://use.perl.org/~Aristotle/journal/30896