Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Paul Rudin Newsgroups: comp.lang.python Subject: Re: Fibonacci series recursion error Date: Sat, 30 Apr 2011 12:29:00 +0100 Lines: 19 Message-ID: <87ei4k0ygz.fsf@rudin.co.uk> References: <87iptw1egh.fsf@rudin.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: individual.net RZXJB2D5VgmnWPY0iRWfEg5+c0ATNvvDTsFHJJFDSIDGQpn3fL X-Orig-Path: hal9000.rudin.co.uk!not-for-mail Cancel-Lock: sha1:nswf0WnPonN/hZbZiTq+fvM24ao= sha1:es9WZyzHTMrJ9nx7QW1m06dAlsw= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4196 Hans Georg Schaathun writes: > On Sat, 30 Apr 2011 06:43:42 +0100, Paul Rudin > 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.