Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://582285]
[choroba]: also, you get stronger by carrying the rune stones along
[erix]: haha
[karlgoethebier]: shmem: This repertoire is a real challenge.
Discipulus mwhwhaa..
[Discipulus]: sucked in traslation.. was'nt a movie?
[karlgoethebier]: adds "Der abenteuerliche Simplicissimus" by Hans Jakob Christoffel von Grimmelshausen
Corion joins another telephone call :-/
[Discipulus]: also The Life and Opinions of the Tomcat Murr
[Discipulus]: I dunno if i can read Dumas in french.. must try some chapter to see

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2017-05-24 08:02 GMT
Find Nodes?
    Voting Booth?