pdcawley,
Eager to try my tail recursion, I tried your example and was bummed when it didn't work. I figured out that to make it work you had to do something like:
print tail_factorial(1, 8);
Where you had to supply an initial total for it to work. Here is a slightly modified version.
sub tail_factorial {
my ($n, $total) = @_;
$total = 1 if ! $total;
return $total if ! $n;
@_ = ($n - 1, $total * $n);
goto &tail_factorial;
}
To verify that it works I tested it for a value of 150 - no deep recursion errors - yeah. Thanks for the p6 weekly summaries too.
Cheers - L~R