The following Clojure code is actually erroneous:
(defn divv [x y z] (if (< x y) z (divv ((- x y) y (+ z 1)))))
as the correct one should be:
(defn divv [x y z] (if (< x y) z (divv (- x y) y (+ z 1))))
but it passes the Clojure REPL, and returns a function. But when calling it (e.g. as (divv 3 2 0), the error will show up
ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn user/divv (NO_SOURCE_FILE:1)
The question is, why isn't the error detected when divv is defined? Since divv is already defined as a function take 3 arguments, why can (divv ((- x y) y (+ z 1))) pass the test?
-andIFnfor the invoke. - ClojureMostlydivv. If failed because(- x y)returned a Long, which isn't anIFn. It never got as far as trying to invokedivv. - Bob Jarvis - Reinstate Monica