2

The function of ^:dynamic is clear (see, for instance, clojure and ^:dynamic). My question: Is ^:dynamic an atomic i.e. indivisible keyword? If not, are any of the below also valid? What do the operators/decorations ^ and : add to the expression?

(def ^:dynamic y 5)    -- Valid (known).
(def dynamic y 5)      -- but the rest of these? ...
(def ^dynamic y 5)
(def :dynamic y 5)
(def ^: y 5)

Alternatively, and maybe there's no clear answer: If ^:dynamic is an indivisible keyword, why attach all the funny punctuation to it?

Community
  • 1
  • 1
Andres Jaan Tack
  • 22,566
  • 11
  • 59
  • 78

1 Answers1

5

This declaration

(def ^:dynamic x 5)

is equivalent to

(def ^{:dynamic true} x 5)

In general ^ followed by a keyword or map is a metadata reader macro. Where followed by a keyword, it sets that keyword to true in the object's metadata map.

To summarize: ^:dynamic is not an "indivisible" keyword; it's a metadata reader macro followed by an ordinary keyword (:dynamic in this case).

Andres Jaan Tack
  • 22,566
  • 11
  • 59
  • 78
Jarlax
  • 1,586
  • 10
  • 20