Possibly Pythonic Tail Call Optimization (TCO/TRE)

Ian Kelly ian.g.kelly at gmail.com
Mon Jul 13 15:46:03 CEST 2015

On Mon, Jul 13, 2015 at 6:34 AM, Chris Angelico <rosuav at gmail.com> wrote:
> On Mon, Jul 13, 2015 at 10:00 PM, Antoon Pardon
> <antoon.pardon at rece.vub.ac.be> wrote:
>> On 07/13/2015 01:28 PM, Chris Angelico wrote:
>>> Why is it worth writing your code recursively, only to have it be
>>> implemented iteratively?
>> Because sometimes, it is easier to think about the problem recursively.
> Can you give me an example that (a) makes a lot more sense recursively
> than iteratively, and (b) involves just one tail call?

Why does (b) matter? If the function has more than one tail call, it
doesn't matter which one you hit -- either way it's a tail call and
the stack frame is no longer needed.

More information about the Python-list mailing list