(defn my-rev [col] (loop [ col col result []] (if (empty? col) result (recur (rest col) (cons (first col) result)))))
Q1.
The JVM cannot optimize recursion, a recursive function that will directly overflow the stack. Therefore, in Clojure, which uses the / recur loop. Thus, without using a function that repeats, deep recursion cannot be defined. (which is also used internally for reuse as a trampoline function.)
Q2.
recursive function with recur, must be tail recursive. If the normal recursive function changes to the tail-recursion function, therefore, as an accumulator, the need to transfer the value of the variable is required.
BLUEPIXY
source share