Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I'm getting Can't dynamically bind non-dynamic var?

Tags:

clojure

I'm trying to use dotrace function of clojure.tools.trace namespace.

(dotrace [my-function] (my-function 5))

But I got this error:

IllegalStateException Can't dynamically bind non-dynamic var: my-ns/my-function clojure.lang.Var.pushThreadBindings (Var.java:339)

What does it mean? why I'm getting it?

(I'm using Clojure 1.3)

like image 844
Chiron Avatar asked Jan 16 '12 02:01

Chiron


1 Answers

I think you need to declare your function as being dynamically bound, e.g.

(def ^:dynamic my-function
   (fn [x] .....))

The reason for that is because if you don't explicitly ask for a dynamic var, Clojure (1.3 upwards) will make it non-dynamic as a performance optimization.

like image 146
mikera Avatar answered Oct 20 '22 22:10

mikera