in reply to Re^2: How will you use state declared variables in Perl6?
in thread How will you use state declared variables in Perl6?
I think that may be a little clearer as well. If I wanted to golf it just a bit more I'd say:sub fib (Int $n) { return 1 if $n < 2; state @seen[$n] //= fib($n-1) + fib($n-2); }
If I wanted to golf it a lot more I'd say:sub fib (Int $n) { $n < 2 or state @seen[$n] //= fib($n-1) + fib($n-2); }
my&fib:={$_<2or state@s[$_]//=fib($_-1)+fib $_-2}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How will you use state declared variables in Perl6?
by BrowserUk (Patriarch) on Nov 05, 2006 at 10:39 UTC | |
by TimToady (Parson) on Nov 06, 2006 at 06:18 UTC |