I am working on clojure koans, and one of the questions in the functions needs an additional explanation for me to “get it” and have a moment of aha. I can write a function that satisfies the question. But I do not quite understand why all the bits work.
Clojure> (= 25 ((fn [a b] (b a)) 5 (fn [n] (* n n))))
true
Question 1.
I do not understand why this causes an error:
Clojure> (= 25 ((fn [b a] (b a)) 5 (fn [n] (* n n))))
java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn
Thus, the only change to the above is to switch the order of b and a. In my brain, I read "a function that takes a and b" or "b and a", but how they are used depends on the subsequent statement in parens. Why is the question in this question?
Questions 2.
Clojure> (= 25 ((fn [a] (5 a)) (fn [n] (* n n))))
java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn
Why, when I substitute the value of b for int, do I present an error?
Quentions 3.
((fn [a b] (b a)) 5 (fn [n] (* n n))))
(b a) b 5, .
, , ?