in reply to Re: Perl 6 is too complex
in thread Perl 6 is too complex
I converted that Perl 6 code to Perl 5 best I could and came up withHere's a slightly more direct conversion
As the comment gives away, this isn't a direct conversion as it isn't using multimethods, so it uses an arg count hack to emulate the behaviour. Also to be an even closer conversion would require apply to tie @squares to a square generator (at least I think that's probably the closest thing you can get to binding to a lazy list in perl6 with raw perl5). So it's certainly no easy task to convert that wee but powerful snippet directly to perl5!sub apply(&@) { ## ack, Class::Multimethods doesn't do variadic args :-/ return if @_ == 1; my($func, $head, @tail) = @_; local $_ = $head; return $func->(), apply($func, @tail); } my @squares = apply { $_ * $_ } 2 .. 5; print join(', ', @squares), $/; __output__ 4, 9, 16, 25
_________
broquaint
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Perl 6 is too complex
by broquaint (Abbot) on Mar 17, 2003 at 11:55 UTC |