Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Fibo Golf challenge on 3 monkeys

by TimToady (Parson)
on Oct 08, 2008 at 07:34 UTC ( [id://715934]=note: print w/replies, xml ) Need Help??


in reply to Re: Fibo Golf challenge on 3 monkeys
in thread Fibo Golf challenge on 3 monkeys

Not implemented yet because we just added it, but in Perl 6 you can just say:
.say for 1,1...{$^a+$^b}
or alternately:
.say for 1,1...&infix:<+>
The latter is likely to be more efficient, since it calls the builtin addition operator without the extra layer of function call implied by the first one (unless we get really fancy with the optimizer and notice it's an identity wrapper).

Either of these works because the ... operator is defined to pass the last N numbers in the list repeatedly to the generator function, where N is determined by the arity of the function, which is 2 in this case.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://715934]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-29 14:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found