Tail recursion Re: list of polynomial functions

Pekka Karjalainen pkarjala at paju.oulu.fi
Tue Jun 20 03:15:28 EDT 2006


In article <1150777400.370686.162340 at i40g2000cwc.googlegroups.com>, 
Matteo wrote:
>This last approach could, at least theoretically, create an arbitrarily
>long list of polys, without overflowing any kind of stack. In practice,
>python does not seem to perform tail recursion optimizations, and conks
>out after makepolys(997) on my machine.
>

You can find out the conking-out limit and change it, within reason.

>>> import sys
>>> help (sys.getrecursionlimit)
[...]
>>> help (sys.setrecursionlimit)
[...]

Here is a recipe for tail recursion optimization at ASPN:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691

Python doesn't do any kind of tail recursion optimization by default
because Guido has decided it shouldn't (at least so far). I'm sure it has
been discussed in detail in Python development forums & lists, but I
don't know those details.

This Google search is a start, but it gives too many hits for me to shift
through now:

http://www.google.fi/search?q=site%3Apython.org+tail+recursion

Pka





More information about the Python-list mailing list