the attached proof-of-concept is almost as ugly as my coroutines module on CPAN,
but i have succeeded in implementing a tail-recursion framework in pure perl.

In order to use it, all modifications to recursive function arguments must be
made directly into @_, but a method is suggested for using named arguments
nonetheless

instead of returning a value, the recursive routine must assign to $_[0] when a
result has been achieved

the magic of nonautovivifying nonexistent hash elements in argument lists
is used to allow the recursive routine to return undef, if that is what it needs
to return, by assigning undef to its $_[0]

The Ackerman function expressed with the framework might look something like

sub Ack {
      tr_dispatch(SUB=>\&tr_Ack, ARGS=>[EMAIL PROTECTED]);
}
sub tr_Ack
{
        my ($x, $y) = \(@_[1,2]);
       $$x == 0 and (  $_[0] = $$y + 1, return);
        $$y == 0 and ($$x--, $$y=1, return);
        $$x-- ; $$y= tr_dispatch(SUB=>\&tr_Ack, ARGS=>[$$x, $$y - 1]);
}

Comments welcome, especially interface improvement ideas.

--
David L Nicol

Reply via email to