Anonymous recursion: Difference between revisions

Content added Content deleted
(Lingo added)
(Added Io entry.)
Line 964: Line 964:
end</lang>
end</lang>
The performance of this second version is 'truly impressive'. And I mean that in a really bad way. By way of example, using default memory settings on a current laptop, a simple recursive non-cached ''fib'' out distanced the non-cached ''fib'' above by a factor of 20,000. And a simple recursive cached version out distanced the cached version above by a factor of 2,000.
The performance of this second version is 'truly impressive'. And I mean that in a really bad way. By way of example, using default memory settings on a current laptop, a simple recursive non-cached ''fib'' out distanced the non-cached ''fib'' above by a factor of 20,000. And a simple recursive cached version out distanced the cached version above by a factor of 2,000.

=={{header|Io}}==
The most natural way to solve this task is to use a nested function whose scope is limited to the helper function.
<lang Io>fib := method(x,
if(x < 0, Exception raise("Negative argument not allowed!"))
fib2 := method(n,
if(n < 2, n, fib2(n-1) + fib2(n-2))
)
fib2(x floor)
)</lang>


=={{header|J}}==
=={{header|J}}==