This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add tail recursion
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: rhettinger, unclezeb
Priority: normal Keywords:

Created on 2007-03-20 17:59 by unclezeb, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg55049 - (view) Author: Tommy Nordgren (unclezeb) Date: 2007-03-20 17:59
Consider the following code:
def fac(m):
    def iter(acc,n):
        if n <= 0 :
            return acc
        else:
            return iter(acc * n, n - 1)
    return iter(1,m)

#When called wtih a large parameter, you get exceed the recursion limit

fac(10000)

In a future release, I suggest updating the interpreter and byte code compiler to handle tail recursion properly as in scheme.
msg55050 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2007-03-20 19:05
This sort of optimization is one of the many that aren't possible without changing the semantics of the language.  Recursive calls use a LOAD_GLOBAL in the function to reference itself.  The value of that global is subject to change outside the body of the function.

History
Date User Action Args
2022-04-11 14:56:23adminsetgithub: 44747
2007-03-20 17:59:36unclezebcreate