[Tutor] recursion depth

Dave Angel davea at davea.name
Thu Jan 9 00:16:03 CET 2014


On Wed, 8 Jan 2014 16:23:06 -0500, eryksun <eryksun at gmail.com> wrote:
> On Wed, Jan 8, 2014 at 3:25 PM, Keith Winston <keithwins at gmail.com> 
wrote:
> > I've been playing with recursion, it's very satisfying.
> >
> > However, it appears that even if I sys.setrecursionlimit(100000), 
it blows
> > up at about 24,000 (appears to reset IDLE). I guess there must be 
a lot of
> > overhead with recursion, if only 24k times are killing my memory?

I can't see the bodies of any of your messages (are you perchance 
posting in html? ),  but I think there's a good chance you're abusing 
recursion and therefore hitting the limit much sooner than necessary. 
 I've seen some code samples here using recursion to fake a goto,  
for example.  One question to ask is whether each time you recurse, 
are you now solving a simpler problem. 

For example,  when iterating over a tree you should only recurse when 
processing a SHALLOWER subtree.

-- 
DaveA



More information about the Tutor mailing list