in reply to Re^4: Variable scope
in thread Variable scope
Pardon me? That example would presumably return a sorting network or certain size and type; I'm not sure what you mean by "sort two networks". Memoization helps there because of recursive structure. I'll give another example that requires no explanation.
And before you ask: no, I do not foresee a need to produce two (different) Fibonacci sequences.sub fibonacci { my $n = shift; return 0+($n==1) if $n < 2; state @mem; $mem[$n] //= fibonacci($n-1) + fibonacci($n-2); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Variable scope
by choroba (Cardinal) on Apr 06, 2018 at 10:56 UTC |