@ deref

syntaxsince v0.0-1853 in clojureEdit

Get the value that a reference is currently referring to. A "reference" can be a atom, delay, or var.

  • @foo - (deref foo)


@foo is sugar for (deref foo).


Quote the form to see how the reader expands it:

;;=> (clojure.core/deref foo)

An atom is a mutable reference to an immutable value.

(def a (atom 1))
;;=> 1

(reset! a 2)
;;=> 2

A delay will evaluate by executing the given expression the first time it is dereferenced.

(def a (delay (do (println "delayed.") 1)))
;; prints:
;;  delayed.
;;=> 1

;;=> 1

Evaluating a symbol naturally dereferences the value of a var. But a var reference can be dereferenced as a roundabout way to obtain its value. (Var references are mainly used to retrieve metadata on that var).

(def ^{:doc "my var"} a 1)
(:doc (meta #'a))
;;=> "my var"

(deref (var a))
;;=> 1

;; combining shorthand forms instead
;;=> 1

See Also:

Reader table @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(defn- macros [ch]
  (case ch
    \" read-string*
    \: read-keyword
    \; read-comment
    \' (wrapping-reader 'quote)
    \@ (wrapping-reader 'clojure.core/deref)
    \^ read-meta
    \` read-syntax-quote ;;(wrapping-reader 'syntax-quote)
    \~ read-unquote
    \( read-list
    \) read-unmatched-delimiter
    \[ read-vector
    \] read-unmatched-delimiter
    \{ read-map
    \} read-unmatched-delimiter
    \\ read-char*
    \% read-arg
    \# read-dispatch