Op Saturday 2 May 2015 16:20 CEST schreef Cecil Westerhof: > I am throwing the cat among the pigeons. ;-) > > In another thread I mentioned that I liked to have tail recursion in > Python. To be clear not automatic, but asked for. > > Looking at the replies I did hit a nerve. But I still want to > continue. > > Some things are better expressed recursively for the people reading > the code. But there are two problems with that: > - You can get out of stack space > - It is less efficient > > Most of the time the first problem is the most important. > > When I write factorial (I know it is already written, but I use it > as an example to show a point), the recursive variant can not be > called with 1.000 without tail recursion. So for functions that > could go very deep, tail recursion would be a blessing. > > By the way: I think that even if the recursion does not go further > as 500, it is still a good idea to use tail recursion. Why use stack > space when it is not necessary?
I pushed the example to GitHub: https://github.com/CecilWesterhof/PythonLibrary/blob/master/mathDecebal.py -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof -- https://mail.python.org/mailman/listinfo/python-list