Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Perl: the Markov chain saw
 
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 examining the Monastery: (11)
As of 2014-04-24 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (565 votes), past polls