in reply to How to understand chapter 6 of Higher Order Perl?
I personally think that that is much easier to understand than the Lisp-like version from the book... It even works faster. What's the point in making Perl look like Lisp anyway? So! I'll answer my own question. 'Anonimous Monk, just rewrite the whole damn chapter in Perl'. Thanks everyone! Especially BrowserUK.sub upto_list { my $from = shift; state $upto = shift; return undef if $from > $upto; return { head => $from, tail => sub { upto_list( $from + 1 ); }, }; } sub show { my $node = shift; my $i = shift // 10; while ($node->{head} && $i-- > 0) { say $node->{head}; $node = $node->{tail}->(); } } show( upto_list( 10, 15 ) );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to understand chapter 6 of Higher Order Perl?
by BrowserUk (Patriarch) on Mar 13, 2014 at 22:07 UTC |