Reputation: 1709
I am defining a function "true-or-false" that will take an argument and print "1" if it is true and "0" if it is false but when I run my function with the argument:
(= 5 4)
it returns the error: "ClassCastException java.lang.Boolean cannot be cast to clojure.lang.IFn"
Code:
(defn true-or-false [x] (if (x)
(println "1")
(println "0")))
(def a (= 5 4))
(true-or-false a)
Upvotes: 0
Views: 834
Reputation: 655
The clojure.lang.IFn
interface provides access to invoking functions, but what you are passing to true-or-false
appears to be a number. You shouldn't be wrapping x
in parentheses inside if
– that would mean you are invoking the x
function call (see clojure.org reference on the if
special form).
Upvotes: 2