Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by TimToady (Parson)
on Nov 05, 2006 at 05:15 UTC ( #582285=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
        sub fib (Int $n) {
            return 1 if $n < 2;
            state @seen[$n] //= fib($n-1) + fib($n-2);
        }
    
  2. or download this
        sub fib (Int $n) {
            $n < 2 or state @seen[$n] //= fib($n-1) + fib($n-2);
        }
    
  3. or download this
        my&fib:={$_<2or state@s[$_]//=fib($_-1)+fib $_-2}
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-10-21 19:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (106 votes), past polls