[Tutor] an error on recursion depth (fwd)

David Mccowan linux1011@HotPOP.com
Wed, 25 Sep 2002 18:02:39 -0500


On Wed, 25 Sep 2002 11:06:40 -0700 (PDT)
Danny Yoo <dyoo@hkn.eecs.berkeley.edu> wrote:

I had this same problem in a program I was writing, my solution was to
use a loop instead.

I not only noticed that it worked but ran much faster.

Most recursive functions can be written as loops and vice versa just by
keeping track of the variable manually.

A good example of this exists in Structure and Interpretation of
Computer Programs, although the book uses scheme its concepts can
easily be applied to most high level programming languanges

http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_1.2.1

In a addition to this section the entire book is online at 

http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html#%_toc_start

> Date: Wed, 25 Sep 2002 12:33:36 +0200
> From: Andrea Valle <marta_andrea@libero.it>
> To: tutor-admin@python.org
> Subject: an error on recursion depth
> 
> Hi list,
> my program stops with this:
> 
> RuntimeError: maximum recursion depth exceeded
> 
> Why? I used the program in Python 1.5.2.: never happened. I think I
> already used it also for exactly the same task (same parameters, same
> complexity) also in 2.1. It's the first time it breaks.
> How can I avoid it?
> 
> thank you
> 
> -a-
> tutor-admin@python.org
> 
> PS:(down I attach the whole final part: the fisrt line is repeat alot
> of times and then you have the ending part)
> 
> 
> File "C:\PROGRA~2\Python\grafoma_geo_quad_set.py", line 42, in
> percorri_arco
>     tre_punti=grafista0.tre_punti(perc, vel, dur)
>   File "C:\PROGRA~2\Python\grafista0.py", line 186, in tre_punti
>     print spazio
>   File "C:\Programmi\Python\Tools\idle\PyShell.py", line 679, in write
>     self.shell.write(s, self.tags)
>   File "C:\Programmi\Python\Tools\idle\PyShell.py", line 666, in write
>     OutputWindow.write(self, s, tags, "iomark")
>   File "C:\Programmi\Python\Tools\idle\OutputWindow.py", line 37, in
>   write
>     self.text.insert(mark, s, tags)
>   File "C:\Programmi\Python\Tools\idle\Percolator.py", line 25, in
>   insert
>     self.top.insert(index, chars, tags)
>   File "C:\Programmi\Python\Tools\idle\PyShell.py", line 146, in
>   insert
>     UndoDelegator.insert(self, index, chars, tags)
>   File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 81, in
>   insert
>     self.addcmd(InsertCommand(index, chars, tags))
>   File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 116, in
> addcmd
>     cmd.do(self.delegate)
>   File "C:\Programmi\Python\Tools\idle\UndoDelegator.py", line 219, in
>   do
>     text.insert(self.index1, self.chars, self.tags)
>   File "C:\Programmi\Python\Tools\idle\ColorDelegator.py", line 73, in
> insert
>     self.notify_range(index, index + "+%dc" % len(chars))
>   File "C:\Programmi\Python\Tools\idle\ColorDelegator.py", line 94, in
> notify_range
>     self.after_id = self.after(1, self.recolorize)
>   File "C:\PROGRA~2\Python\lib\lib-tk\Tkinter.py", line 442, in after
>     name = self._register(callit)
>   File "C:\PROGRA~2\Python\lib\lib-tk\Tkinter.py", line 988, in
>   _register
>     f = CallWrapper(func, subst, self).__call__
> RuntimeError: maximum recursion depth exceeded
> 
> Andrea Valle
> via Lanzo 108
> 10073 - Cirič (TO)
> ITALIA
> 011/921 45 84 - 349/55 47 343
> 
> 
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor