Why no tailcall-optimization?
tjreedy at udel.edu
Tue Sep 23 10:37:25 CEST 2008
> Why doesn't Python optimize tailcalls? Are there plans for it?
I started to write an article on this but it disappeared....
So short answer:
1. Unless down very carefully, in a way that would slow things down, it
would change the semantics of Python.
2. It is usually trivial to convert to a while loop, which amounts to
in-frame recursion. If using tail-recursion requires a nested inner
function to avoid repeating one-time initialization or exposing the
cumulation variable, writing the loop is easier since no nested function
3. In Python, for loops are usually better for processing iterables,
which covers most uses of induction (recursion/iteration).
Terry Jan Reedy
More information about the Python-list