[EMAIL PROTECTED] wrote:
> It appears recursion is nice but *iteration* takes up less space than
> recursion?....
> 
> And tail recursion allows us to nest our recursion as insanely as we want
> knowing that compiler/interpreter will convert it under the hood to
> a for loop for us!?!??
> 
> I tried this in Python....
> 
> def f(x):
>       print x,
>       f(x)
> 
> It didn't go on forever but bombed with a "maximum recursion depth exceeded"
> message.
> 
> If all the smart kids know about tail recursion then how come the Python
> interpreter couldn't/didn't use tail recursion to prevent my infinite loop 
> from
> bombing?

Hey, I can answer that one! Tail recursion does not fix infinite
recursion for you.

The problem with your example would occur in any language.
The problem is that your recursive function has no end condition.

It normally would look something like

def f(x):
  print x
  x = next(x)
  if itstimetostop(x):
        return
  f(x)

where next(x) might be x -> x-1
and itstimetostop might be x < 0

The first thing to look for in any recursive or iterative code is the
termination condition & logic.

Regards,
..jim

-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to