Possibly Pythonic Tail Call Optimization (TCO/TRE)

Chris Angelico rosuav at gmail.com
Tue Jul 14 16:07:18 CEST 2015

On Wed, Jul 15, 2015 at 12:02 AM, Antoon Pardon
<antoon.pardon at rece.vub.ac.be> wrote:
> On 07/14/2015 03:43 PM, Chris Angelico wrote:
>> On Tue, Jul 14, 2015 at 11:38 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>>> Chris Angelico <rosuav at gmail.com>:
>>>> On Tue, Jul 14, 2015 at 10:28 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>>>>> I would rather optimize by default and disable optimizations with
>>>>> --debug or equivalent.
>>>> That assumes that it's simply an optimization. This is a distinct
>>>> semantic change.
>>> No, tail call optimization doesn't change the behavior of the program,
>>> for the worse anyway.
>> It does, because you lose traceback records. That's pretty significant
>> when you come to try to debug something.
> I doubt it would be really significant. Not compared to writing it iteratively.
> When you write it iteratively, you don't get to keep a traceback record per time
> you go throught the loop. So the traceback records you loose in tale call elimination
> would be the traceback records you wouldn't have anyway in the iterative version.
> So how would this be significant?

You're proposing making _every_ instance of "return func(...)" into
this kind of thing. That's not always recursion, and it's certainly
not always clear what called what to get you there.


More information about the Python-list mailing list