In addition to with-meta
, there are a number of short-hand reader
macros for affixing metadata to objects.
^{:doc "How obj works!"} obj
- Sets the metadata ofobj
to the provided map. Equivalent to(with-meta obj {:doc "How obj works!"})
.^:dynamic obj
- Sets the given keyword totrue
in the object's metadata. Equivalent to^{:dynamic true} obj
.^String obj
- Sets the value of:tag
key in the object's metadata. Equivalent to^{:tag java.lang.String} obj
. Used to hint an objects type to the Clojure compiler. See Java Interop: Type Hints for more information and a complete list of special type hints.
Each of these short-hands is a reader macro ([The Reader: Macro Characters](http://clojure.org/reader#The Reader--Macro characters))
and applies to the expression that follows it. It is possible to add multiple pieces of metadata by chaining short-hands together. For example: ^:dynamic ^ints obj
would apply both the :dynamic
flag and ints
type-hint to obj
.