#' var

syntaxsince v0.0-1853 in clojureEdit

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)

Details:

#'foo is sugar for (var foo).

Mainly used in conjunction with meta.


Examples:

Access the metadata of a var:

(def x 123)
(meta #'x)
;;=> {:arglists (), :test nil, :name x, :column 1, :line 1, :file "<cljs repl>", :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

See Also:


Reader table @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(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))