Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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 perusing the Monastery: (10)
As of 2015-07-29 08:32 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 (261 votes), past polls