in reply to Re: Pure Perl tail call optimization
in thread Pure Perl tail call optimization
Your code is better written as
sub loop_factorial { my ($n, $total) = @_; $total = 1 unless $total; while ($n) { ($n,$total) = ($n - 1, $total * $n); } return $total }
Which is more efficient, and is IMO a better example of what a compiler that optimizes tail recursion would convert it to.
First they ignore you, then they laugh at you, then they fight you, then you win.
-- Gandhi
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Pure Perl tail call optimization
by Limbic~Region (Chancellor) on Mar 09, 2004 at 19:51 UTC | |
by demerphq (Chancellor) on Mar 10, 2004 at 08:48 UTC | |
by tilly (Archbishop) on Mar 11, 2004 at 03:14 UTC | |
by pdcawley (Hermit) on Mar 19, 2004 at 21:19 UTC |