Recursive calls and stack

Neil Cerutti horpner at yahoo.com
Thu Feb 15 11:37:19 EST 2007


On 2007-02-15, Gabriel Genellina <gagsl-py at yahoo.com.ar> wrote:
> En Wed, 14 Feb 2007 10:41:53 -0300, Neil Cerutti <horpner at yahoo.com>  
> escribió:
>> So the effect is that mutual recursion isn't actually any
>> harder.
>
> But some kind of language support is required in this case. At
> least I  don't know how to handle mutual recursion (apart from
> inlining one  function inside the other...). But I'm certainly
> not a "program  transformation guru" (neither a novice!) so I
> would not be surprised if  someone says it can be done...

What happens (using the model of an imaginary virtual machine,
perhaps like the Python interpreter) is the following.

A normal function call pushes a call-frame onto a stack. The
call-frame contains information necessary for returning from the
function, and usually a place to store its local variables and
parameters.

A function called in "tail" position simply overwrites the
current call-frame with the new one instead of pushing it onto
the stack.

-- 
Neil Cerutti
The church will host an evening of fine dining, superb entertainment, and
gracious hostility. --Church Bulletin Blooper



More information about the Python-list mailing list