Unfortunately, first of all it's impossible to computationally detect an
infinite loop. It's loosely the Halting Problem solved by Turing back in the
old days.

Also recursion just uses the system stack as a data structure, so iteration
typically is not only faster in implementation due to less pushing and
popping of stack frames (of course if you use a smarter data structure) on
the runtime stack, but can typically use less memory because of all of the
unnecessary overhead of a function call tree managed in an ultra-generic
fashion by your computer.

-Tom

On Jan 23, 2008 9:58 PM, <[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?
>
> Chris
>
> --
> [email protected]
> http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg
>



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

Reply via email to