[Python-ideas] Tail Call Optimization (was Re: Tail recursion elimination)

Nick Coghlan ncoghlan at gmail.com
Sun Jan 19 13:31:06 CET 2014


On 19 January 2014 22:12, Terry Reedy <tjreedy at udel.edu> wrote:
> TCO (Tail Call Optimization) means that when TCO is in effect and a tail
> call "return f(<args>)" is executed, the current execution context (stack
> frame) is used for the call instead of allocating a new one. What is
> 'optimized' is space usage. The effect on time is not clear.
>
> On 1/18/2014 7:45 PM, Steven D'Aprano wrote:
>
>> What makes you say that it is "non-pythonic"? You seem to be assuming
>> that *by definition* anything written recursively is non-pythonic. I do
>> not subscribe to that view.
>
>
> Neither do I.

Guido is on record as preferring iterative algorithms as more
comprehensible for more people, and explicitly opposed to adding tail
call optimisation. I tend to agree with him - functional programming
works OK in the small (and pure functions are a fine tool for managing
complexity), but to scale up in a way that fits people's brains, you
need to start writing code that looks more like a cookbook.

If you want inspiration on how to design a language for typical human
thought patterns, look to cookbooks, training guides and operator
manuals, not mathematics.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list