Recursive calls and stack

Gabriel Genellina gagsl-py at yahoo.com.ar
Thu Feb 15 13:36:35 EST 2007


En Thu, 15 Feb 2007 13:37:19 -0300, Neil Cerutti <horpner at yahoo.com>  
escribió:

> 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.

This is the "kind of language support" menctioned. For tail recursion you  
don't require that support.

-- 
Gabriel Genellina




More information about the Python-list mailing list