Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: fibonacci numbers using subroutine?

by TimToady (Parson)
on Aug 20, 2010 at 18:33 UTC ( #856341=note: print w/ replies, xml ) Need Help??


in reply to Re^2: fibonacci numbers using subroutine?
in thread fibonacci numbers using subroutine?

In practice, though, if you're going to reuse a series in your Perl 6 program, you'll want to memoize the series by binding the series to an array, like this:

my @fib := (0,1, *+* ... *); say @fib[8]; say @fib[9]; # doesn't recalculate fib(8)
Both lists and arrays can be lazily infinite in Perl 6; the only real difference is whether the values are kept in an indexable form as they are generated. Note also that the memoization naturally uses an array rather than a hash in this case, which saves memory over those memoization techniques that must assume a hash for generality.


Comment on Re^3: fibonacci numbers using subroutine?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (12)
As of 2015-07-06 15:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (77 votes), past polls