Fibonacci series recursion error

Paul Rudin paul.nospam at
Sat Apr 30 13:29:00 CEST 2011

Hans Georg Schaathun <hg at> writes:

> On Sat, 30 Apr 2011 06:43:42 +0100, Paul Rudin
>   <paul.nospam at> wrote:
> :  Writing recurive code is acceptable and is a nice clear way of
> :  expressing things when you have naturally recursive data structures, and
> :  can lead to perfectly good compiled code. The problem in CPython is the
> :  lack of tail optimization, so it's not a good idea for python . Some
> :  language standards guarantee tail optimization...
> Well, if you run into a case where tail optimisation really makes a
> difference, you probably want to reimplement it for a compiler that
> guarantees tail optimisation, rather than reimplement it without
> recursion within python.

Clearly it makes a difference in any case where you'd hit the recursion
limit. It's no big deal to do your own unwinding of the recursion to a
loop, but the code is typically less clear.

More information about the Python-list mailing list