tail-rec decorator, well still blows the stack...
David Wahler
dwahler at gmail.com
Tue Jul 22 00:24:01 EDT 2008
On Mon, Jul 21, 2008 at 10:01 PM, ssecorp <circularfunc at gmail.com> wrote:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691
>
> so I try it and when I run:
> @Decorators.tail_recursion
> def fibtr(n):
> def fibt(a, b, n):
> if n <= 1:
> return b
> else:
> return fibt(b, a + b, n - 1)
> if n == 0:
> return 0
> else:
> return fibt(0, 1, n);
>
> it still blows the stack. so what is the point? is it impossible to
> get "real" tail-recursion in Python?
Python does not perform tail-call elimination, and there are currently
no plans to make it do so. See
http://mail.python.org/pipermail/python-dev/2004-July/046171.html and
the ensuing discussion for an explanation.
More information about the Python-list
mailing list