What would jvm have to sacrifice to implement tail call optimization?

People say that the clojure implementation is excellent, except for limiting the lack of tail call optimization - limiting the jvm implementation, not the clojure.

http://lambda-the-ultimate.org/node/2547

It was said that for the implementation of TCO in Python donates

  • stack trace dumps and
  • regular debugging.

Explain to me what a big problem with tail call optimization is and why Python needs it

Have the same sacrifices been made to implement TCO in jvm? Will anything else be sacrificed?

+3
source share
3 answers

( , il ), .Net 64- JIT .

, , :

, , , , , .

, JVM .

, , , JIT , , , Debug. , , . "" .

, , , / ( , ), / .
, , , , .

+6

JVM. wiki page .

+2

, . , TCO , .

It is also interesting to note that Clojure has a "recur" function that does not require a stack to circumvent this limitation for current versions of the JVM.

Example:

(defn triangle [n accumulator] 
  (if 
    (<= n 0)  
      accumulator
      (recur (dec n) (+ n accumulator))))

(triangle 1000000 0)

=> 500000500000     (note stack does not explode here!)
0
source

Source: https://habr.com/ru/post/1710671/


All Articles