sub tail_factorial {
my($total, $n) = @_;
if ($n == 0) {
return $total;
}
else {
return tail_factorial($total * $n, $n - 1)
}
}
####
sub tail_factorial {
my $total = shift; my $n = shift;
if ($n == 0) {
return $total;
}
else {
@_ = ($n * $total, $n - 1);
goto &tail_factorial;
}
}
##
##
sub run_ops {
my $self = shift;
EVAL_DISPATCH: while (1) {
my $expr = $self->expr;
if ($expr->is_self_evaluating) {
$self->{value} = $expr;
}
else {
$expr->evaluate($self);
}
while (1) {
my $cont = $self->continuation;
if (ref($cont) eq 'CODE') {
$cont->($self);
}
elsif (!ref($cont)) {
return $self->{value} if $cont eq 'return';
$self->$cont();
}
else {
die "Broken continuation: $cont"
}
}
}
}