On 8/20/2010 1:17 PM, John Bokma wrote:
John Nagle<na...@animats.com> writes:
Python does not do tail recursion, so using recursion
where iteration could do the job is generally a bad idea. Scheme, on
the other hand, always does tail recursion where possible.
I think you mean tail recursion optimization / elimination.
Python does tail recursion:
Not very well.
def cnt(n) :
if n > 0 :
cnt(n-1)
This will work for up to cnt(998), but at cnt(999), CPython
reports "RuntimeError: maximum recursion depth exceeded."
Yes, you can increase the recursion depth, but that case
shouldn't be compiled to recursion at all.
John Nagle
--
http://mail.python.org/mailman/listinfo/python-list