Neil Cerutti wrote: > On 2007-06-12, Anders J. Munch <[EMAIL PROTECTED]> 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 counters. - Anders -- http://mail.python.org/mailman/listinfo/python-list