On Sep 22, 9:13 pm, process <[EMAIL PROTECTED]> wrote: > Why doesn't Python optimize tailcalls? Are there plans for it?
The main technical difficulty is that the compiler has to know whether the function returns a tail call or not at compile time. But because Python is fully dynamic with regard to type, the compiler never(**) knows anything about any object other than "it's an object". The compiler doesn't even know if the object is callable. Probably it would be possible to achieve this optimization without involving the compiler, but it'd be at cost of great complexity and probably would negatively affect ordinary function calls (which are already slow enough). (BTW, if you're just talking about converting simple tail-recursive functions, and not about general tail-call optimization, then I'd suggest a third-party package would be better for that, since it would be a pretty complex thing that would benefit only a tiny fraction of users.) Carl Banks (**) Actually the compiler can do some compile-time constant expression folding, but that's about it. Otherwise it's object agnostic. -- http://mail.python.org/mailman/listinfo/python-list