[ python-Feature Requests-1684603 ] Add tail recursion
SourceForge.net
noreply at sourceforge.net
Tue Mar 20 20:05:09 CET 2007
Feature Requests item #1684603, was opened at 2007-03-20 12:59
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1684603&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
>Category: Parser/Compiler
>Group: Python 2.6
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Private: No
Submitted By: Tommy Nordgren (unclezeb)
Assigned to: Nobody/Anonymous (nobody)
Summary: Add tail recursion
Initial Comment:
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.
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2007-03-20 14:05
Message:
Logged In: YES
user_id=80475
Originator: NO
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.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1684603&group_id=5470
More information about the Python-bugs-list
mailing list