Tail recursion to while iteration in 2 easy steps

random832 at fastmail.us random832 at fastmail.us
Mon Oct 7 17:27:18 EDT 2013


On Sat, Oct 5, 2013, at 3:39, Antoon Pardon wrote:
> What does this mean?
> 
> Does it mean that a naive implementation would arbitrarily mess up
> stack traces and he wasn't interested in investigating more
> sophisticated implementations?
> 
> Does it mean he just didn't like the idea a stack trace wouldn't be a
> 100% represenatation of the active call history?
> 
> Does it mean he investigated more sphisticated implementations but found
> them to have serious short comings that couldn't be remedied easily?

The entire point of tail call optimization requires not keeping the
intervening stack frames around, in _any_ form, so as to allow
arbitrarily deep recursion without ever having the possibility of a
stack overflow. An implementation which reduced but did not eliminate
the space used per call would not be worthwhile because it would not
enable the recursive functional programming patterns that mandatory tail
call optimization allows.

You could require that an "optimizable tail call" be made explicit.
Actually, I suspect it might be possible to do this now, by abusing
exception handling as a control flow mechanism.



More information about the Python-list mailing list