0

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)

1 Answer 1

2

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.