Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For TRE: http://neopythonic.blogspot.com/2009/04/tail-recursion-elimi...

For the GIL, there are alternative implementations of Python (Jython, IronPython, etc.)



Hm... Python only supports 1000 recursions? That seems unsafe. It seems like anyone who writes functional-style code will run the risk of a stack overflow.


Believe it or not, it's actually deliberate. And not that uncommon in other languages too. The only way you can realistially have 'unlimited' recursion is to use tail call optimisation, which is deliberaterly not implemented in python:

http://neopythonic.blogspot.co.uk/2009/04/final-words-on-tai...

Is Guido's take on it.

Essentially, as I understand it, his take is that massive recursion is confusing, and 'unpythonic'. And with the whole 'explicit is better than implicit' thing, I guess there is a point.

Some times recursion is the best/most obvious solution, and then it is a bit annoying to not have TCO, but you can usually work around it.


You can increase the recursion limit like this:

import sys

sys.setrecursionlimit(x)

Kind of a "hackish" way to do things but you can do it if you need to.


^Although I think the idea is that you shouldn't need to. Any recursive implementation can either be easily translated to work iteratively, or can be implemented in such a way that 1000 levels of recursion should be more than enough.

For example, 1000 levels of recursion is more than enough to count all the nodes in a binary tree unless the tree is extremely poorly balanced or inordinately large.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: