Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93757

Re: Possibly Pythonic Tail Call Optimization (TCO/TRE)

References <CAD+URuj-4e62-9hvpiLsrBP1M6kXRyZhZ6XyL01gWWnDoShvNg@mail.gmail.com> <CAPTjJmrnd2cdA75ROZUKsJfYMdYUXkxRbEN50UE_-r0Jg=c5nQ@mail.gmail.com> <55A3A853.4040006@rece.vub.ac.be> <CAPTjJmr92j+2DDPsZxynoHyZTTCpc-48cWCVrx_fT3dA0j_Osg@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2015-07-13 07:46 -0600
Subject Re: Possibly Pythonic Tail Call Optimization (TCO/TRE)
Newsgroups comp.lang.python
Message-ID <mailman.465.1436795213.3674.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Jul 13, 2015 at 6:34 AM, Chris Angelico <rosuav@gmail.com> wrote:
> On Mon, Jul 13, 2015 at 10:00 PM, Antoon Pardon
> <antoon.pardon@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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Possibly Pythonic Tail Call Optimization (TCO/TRE) Ian Kelly <ian.g.kelly@gmail.com> - 2015-07-13 07:46 -0600

csiph-web