syntax | since v0.0-1853 | in clojure | Edit |
To retrieve metadata like where a var was defined, we need to refer to the var itself. It is therefore helpful to be aware of the following subtle differences:
foo
=> returns value bound to foo'foo
=> returns the symbol foo (which is just a name)#'foo
=> returns the foo var itself (for retrieving metadata like where it was defined)Quote the form to see how the reader expands it:
'#'foo
;;=> (var foo)
Access the metadata of a var:
(def x 123)
(meta #'x)
;;=> {:arglists (), :test nil, :name x, :column 1, :line 1, :file "", :doc nil, :ns cljs.user}
Deref a var for a roundabout way to retrieve its value:
(def x 123)
@#'x
;;=> 123
;; same as above
(deref (var x))
;;=> 123
(defn- dispatch-macros [ch]
(case ch
\^ read-meta ;deprecated
\' (wrapping-reader 'var)
\( read-fn
\= read-eval
\{ read-set
\< (throwing-reader "Unreadable form")
\" read-regex
\! read-comment
\_ read-discard
\? read-cond
\: read-namespaced-map
\# read-symbolic-value
nil))