[Python-Dev] Proper tail recursion (original) (raw)

Michael Chermside mcherm at mcherm.com
Thu Jul 15 19:24:53 CEST 2004


> Well, I think I understand Jython well enough to provide the > assurance: Jython is (intentionally, and for good reason) designed > to utilize the JVM's call stack. Thus Jython cannot support tail > call elimination unless it is run on a JVM which does tail call > elimination.

I originally thought I'd need to use gcc's tail call optimization to achieve my aim (since CPython works the same way), but it turned out a simple loop would suffice. Unless Jython's implementation is radically different (i.e. it doesn't pass frame objects to a function that evaluates them) then it should be able to be implemented similarly.

Like I said, Jython uses the JVM's call stack. So it certainly doesn't pass frame objects to a function that evaluates them... Jython stack frames are actual Java stack frames. This is part of why Jython does such an incredibly good job of integrating tightly with Java -- Java any Jython functions (methods) can call each other freely because they're practically the same thing.

-- Michael Chermside



More information about the Python-Dev mailing list