user5628280
user5628280

Reputation:

Clojure binding : Can't dynamically bind non-dynamic var

I'm starting with Clojure and trying to bind (or true) to be (true). I get the following error:

CompilerException java.lang.ClassCastException: java.lang.Boolean cannot be cast to clojure.lang.IFn, compiling:(myproject\core.clj:8:26)

Here's the code:

(declare ^:dynamic or)
(binding [or true] (true))

If I just do

(binding [or true] (true))

I get:

CompilerException java.lang.IllegalStateException: Can't dynamically bind non-dynamic var: clojure.core/or, compiling:(myproject\core.clj:5:30)

Upvotes: 0

Views: 260

Answers (1)

leontalbot
leontalbot

Reputation: 2543

true is not a function. It shouldn't be in parenthesis.

(declare ^:dynamic or) (binding [or true] true)

Note that or already refers to clojure.core/or. You could name your var or- instead.

Upvotes: 1

Related Questions