Re: Why is this blowing the stack, thought it was tail-recursive...

2008-07-16 Thread Lie
On Jul 13, 8:44 pm, Fuzzyman <[EMAIL PROTECTED]> wrote: > On Jul 13, 7:56 am, Steven D'Aprano <[EMAIL PROTECTED] > > > > cybersource.com.au> wrote: > > On Sat, 12 Jul 2008 19:25:18 -0400, Terry Reedy wrote: > > > ssecorp wrote: > > >> def fib(n): > > >>     def fibt(a, b, n): > > >>         if n <=

Re: Why is this blowing the stack, thought it was tail-recursive...

2008-07-13 Thread Fuzzyman
On Jul 13, 7:56 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Sat, 12 Jul 2008 19:25:18 -0400, Terry Reedy wrote: > > ssecorp wrote: > >> def fib(n): > >>     def fibt(a, b, n): > >>         if n <= 1: > >>             return b > >>         else: > >>             return fib

Re: Why is this blowing the stack, thought it was tail-recursive...

2008-07-13 Thread Steven D'Aprano
On Sat, 12 Jul 2008 19:25:18 -0400, Terry Reedy wrote: > ssecorp wrote: >> def fib(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

Re: Why is this blowing the stack, thought it was tail-recursive...

2008-07-12 Thread Terry Reedy
ssecorp wrote: def fib(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); and can memoization speed up this even more? tesintg with memoization doesnt

Re: Why is this blowing the stack, thought it was tail-recursive...

2008-07-12 Thread Scott David Daniels
ssecorp wrote: used> and can memoization speed up this even more? Generators get you to an even clearer Fibonacci expression. def _Fibonacci_gen(): a, b = 1, 0 while True: a += b yield a b += a yield b Here's how to use

Re: Why is this blowing the stack, thought it was tail-recursive...

2008-07-12 Thread Marc Christiansen
ssecorp <[EMAIL PROTECTED]> asked: > Why is this blowing the stack, thought it was tail-recursive... Because python does no tail-call optimization. Ciao Marc -- http://mail.python.org/mailman/listinfo/python-list

Why is this blowing the stack, thought it was tail-recursive...

2008-07-12 Thread ssecorp
def fib(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); and can memoization speed up this even more? tesintg with memoization doesnt really say anythin