Python's "only one way to do it" philosophy isn't good?

Anders J. Munch 2007 at
Wed Jun 13 18:57:47 CEST 2007

Neil Cerutti wrote:
> On 2007-06-12, Anders J. Munch <2007 at> wrote:
>> Converting tail-recursion to iteration is trivial, and
>> perfectly reasonable for a human to do by hand.  
> For simple recursive tail calls, yeah, it can be. Translating a
> tail-recursive Factorial function into a while loop is easy. But
> tail-call optimization technically works for any tail-call,
> including mutual recursion, and non-recursive tail-calls. You
> can't reasonably hand-optimize away the stack frame for all
> tail-calls.

I may have misunderstood, I thought we were talking about tail recursion only. 
The general tail-call optimisation, where all leaf calls become jumps and the 
called function usurps the current stack frame, is a different ballgame 
entirely.  There's no pure-Python transformation for that, but that still 
doesn't mean you need CPS.

General tail-call optimisation is of course completely out-of-bounds for Python, 
because it ruins tracebacks.  Unlike tail recursion, which could use recursion 

- Anders

More information about the Python-list mailing list