Possibly Pythonic Tail Call Optimization (TCO/TRE)

Marko Rauhamaa marko at pacujo.net
Tue Jul 14 14:08:42 CEST 2015


Chris Angelico <rosuav at gmail.com>:

> On Tue, Jul 14, 2015 at 3:41 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> Tail-call optimization has nothing to do with converting algorithms into
>> iterations. It's a prosaic trick of dropping an unneeded stack frame
>> before making a function call.
>>
>>> The claim that TCO means you don't need stack space for all those
>>> levels of recursion doesn't work if you still need stack space for all
>>> those levels of recursion *before* you get to the tail call.
>>
>> Nobody is making that claim.
>
> Actually, that claim was made - that Python's stack would overflow if
> you didn't optimize tail calls away. I don't feel like digging up
> through the history to find out who first made the claim, but it was
> made in this thread.

Nobody is making the claim that optimizing tail calls *always* saves you
from stack overflows.

Optimizing tail calls *sometimes* saves you from stack overflows.


Marko


More information about the Python-list mailing list