thanks i already have perfect iterative versions of fibonacci.
def fib(n):
a, b = 1, 0
while n:
a, b, n = b, a+b, n-1
return b
I know the example is not the way to write pythonic code, I was just
learning about decorators and then I saw this example and tried it
out.
but than
ssecorp 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
On Mon, Jul 21, 2008 at 10:01 PM, ssecorp <[EMAIL PROTECTED]> 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:
>
I my function not proper tail-recursion?
because this doesn't blow the stack:
#!/usr/bin/env python2.4
# This program shows off a python decorator(
# which implements tail call optimization. It
# does this by throwing an exception if it is
# it's own grandparent, and catching such
# exceptions