Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^5: How will you use state declared variables in Perl6?

by TimToady (Parson)
on Nov 06, 2006 at 06:18 UTC ( #582383=note: print w/ replies, xml ) Need Help??


in reply to Re^4: How will you use state declared variables in Perl6?
in thread How will you use state declared variables in Perl6?

You must be running an older pugs. In fact, the current (working) version in the pugs repository (r14657) now reads:

sub fib (UInt $n) { (state $seen = [0,1,1]).[$n] //= fib($n-1) + fib($n-2); }
It would also work as state @seen = 0,1,1 except there's a bug with initializing state variables using a list that causes it to reinitialize every time instead of just the first time, which, while it lets it run, kinda defeats the memoization...


Comment on Re^5: How will you use state declared variables in Perl6?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-12-21 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (103 votes), past polls