in reply to Re: How will you use state declared variables in Perl6?
in thread How will you use state declared variables in Perl6?
I just added an example to pugs which uses state for memoization.
use v6; my $n = @*ARGS[0] // 42; say fib($n); sub fib (Int $n) { state %seen; return 1 if $n < 2; %seen{$n - $_} //= fib($n - $_) for 1 .. 2; return %seen{$n - 1} + %seen{$n - 2}; }
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How will you use state declared variables in Perl6?
by TimToady (Parson) on Nov 05, 2006 at 05:15 UTC | |
by BrowserUk (Patriarch) on Nov 05, 2006 at 10:39 UTC | |
by TimToady (Parson) on Nov 06, 2006 at 06:18 UTC | |
|
Re^3: How will you use state declared variables in Perl6?
by Juerd (Abbot) on Nov 05, 2006 at 23:50 UTC | |
by TimToady (Parson) on Nov 06, 2006 at 06:07 UTC | |
by Juerd (Abbot) on Nov 06, 2006 at 09:32 UTC |