[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?
>   
feature != bug

So, four things:

1) The Python guys aren't exactly huge on performance optimizations, so
don't look to them for optimizations unless you know they have them.
2) http://python.org/doc/current/lib/module-sys.html
See "setrecursionlimit(limit)"
3) There are hacky ways to implement tail recursion in Python:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/474088
4) I believe Stackless Python does indeed do tail recursion.

--Chris

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

Reply via email to