4 ms·
Let's just pretend we are binding values. There are ways to make perl look like you are doing parameter assignment. sub { my $builder = shift;
by Xurinos 15y ago
Let'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.