[Tutor] strange recursion result
Mon, 8 Jan 2001 17:38:24 -0600 (CST)
On Sun, 7 Jan 2001, Daniel Yoo wrote:
> 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.
Well, I didn't get that message but that appears to be what's
happening. sys.getrecursionlimit() gives me 1000, which is where the
problem started occuring. I'm using Python 2.0 on MkLinux R1. I upgraded
to 2.0 soon after it came out, I was anxious to see what was new. So far
the only thing I've noticed is the appearance of +=, which I was really
glad to see, it just looks cleaner to me.
> 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
> recursive-like stuff with for/while loops, so it's a bit less functional
> in terms of recursion.
I don't have much of a programming background, the first thing I tried to
learn was C++, which I found to be impractical for the types of things I
want to do. Then came PHP, which is great, but seemed limited to web
pages (yeah I know it can be used for shell scripting too). Then after
reading Phillip Greenspun's book, I looked at TCL. It was about that time
that I started hearing alot of good things about python (Linux Journal had
a special issue about it). The whitespace thing and the strange for
statements initially turned me off, but after I started using python, I
quickly found that those were big advantages and I really like it now. My
only wish now is that I could use python like I use PHP, on a web page
inside tags like <? ?> (ie. non-cgi). Unless I've overlooked something, I
don't think that's possible.
> for i in range(n):
> sum = sum + i
That actually works alot better since its not limited by the recursion
limit and its also easier to understand. I think I was making things more
difficult by using recursion, although I'm glad to find out about the
limit, I might need to know that some day.