Tail recursion to while iteration in 2 easy steps

Alain Ketterlin alain at dpt-info.u-strasbg.fr
Tue Oct 8 04:41:41 EDT 2013


random832 at fastmail.us writes:

> On Mon, Oct 7, 2013, at 13:15, Alain Ketterlin wrote:
>> That's fine. My point was: you can't at the same time have full
>> dynamicity *and* procedural optimizations (like tail call opt).
>> Everybody should be clear about the trade-off.
>
> Let's be clear about what optimizations we are talking about. Tail call
> optimization, itself, doesn't care _what_ is being called. It can just
> as easily mean "erase its own stack frame and replace it with that of
> another function" as "reassign the arguments and jump to the top of this
> function". Some people have introduced the idea of _further_
> optimizations, transforming "near" tail recursion (i.e. return self()+1)
> into tail recursion, and _that_ depends on knowing the identity of the
> function (though arguably that could be accounted for at the cost of
> including dead code for the path that assumes it may have been changed),
> but tail call optimization itself does not.

You're right, thanks for the clarification.

-- Alain.



More information about the Python-list mailing list