in reply to Re^4: Behold! The power of recursion.
in thread Behold! The power of recursion.
Now one problem of course is that perl does not do this type of optimization :)Sure, but you can tell it to do that. :-)
sub factorial { my ($n, $accumulator) = @_; $accumulator ||= 1; if ($n == 0) { return $accumulator; } @_ = ($n - 1, $n * $accumulator); goto &factorial; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Behold! The power of recursion.
by Roy Johnson (Monsignor) on Apr 08, 2005 at 21:39 UTC | |
by ikegami (Patriarch) on Feb 17, 2006 at 23:17 UTC | |
by diotalevi (Canon) on Feb 18, 2006 at 00:26 UTC | |
by BrowserUk (Patriarch) on Feb 18, 2006 at 04:53 UTC |