[Tutor] strange recursion result

D-Man dsh8290@rit.edu
Mon, 8 Jan 2001 09:52:56 -0500

On Sun, Jan 07, 2001 at 02:22:48PM -0800, Daniel Yoo wrote:
| On Sun, 7 Jan 2001 mbc2@netdoor.com wrote:


| You probably got the following message:
| ###
| RuntimeError: Maximum recursion depth exceeded
| ###
| which means that it just hit its limits.  The Python implementors are
| probably planning to support recursion to arbitrary depths in the future,
| but this hasn't been done yet.
| Are you coming from a Scheme background?  Since Scheme's only iteration
| consists of recursion, the implementors of Scheme made extra sure that
| they didn't impose limits to recursion.  Python, on the other hand, does

Actually, Scheme does include a loop construct.  (but it might, not, I
might be confusing it with Common Lisp)  Scheme doesn't have a
recursion limit iff the fuction(s) are tail-recursive.  The posted
python function was not tail recursive, so it wouldn't have that
optimization.  Python doesn't do any tail-recursion optimization.

| recursive-like stuff with for/while loops, so it's a bit less functional
| in terms of recursion.


| Apologies: it feels like a disappointing answer to say "It won't work
| yet"; does anyone have any suggestions or comments?

You could try Stackless Python.  The recursion limit in (normal)
Python comes from the python stack being intertwined with the C stack
and the C stack has a limit.  Stackless Python separates the stacks so
that the C stack can be unwound before the Python stack is.  This
allows the python stack to be "inifinite" (until the machines memory
is used up).

I'd like to see python do tail-recursion optimizations, but I don't
actually use recursion very often anyways.