{} map

syntaxsince v0.0-1853 in clojure in ednEdit

A map associates keys with values.

  • {...}
  • {:foo 1}
  • {:foo 1, :bar 2} - comma is optional
  • {[1 2] "foo"} - keys and values can be any type (even collections)

Details:

Creates a map. Must contain pairs of key-values. Keys and values can be any type.


Examples:

{:foo 1 :bar 2}
;;=> {:foo 1, :bar 2}

Use any value as a key:

(def m {[1 2] 3})
(get m [1 2])
;;=> 3

See Also:


Reader code @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(defn- read-map
  [rdr _ opts pending-forms]
  (let [[start-line start-column] (starting-line-col-info rdr)
        the-map (read-delimited :map \} rdr opts pending-forms)
        map-count (count the-map)
        [end-line end-column] (ending-line-col-info rdr)]
    (when (odd? map-count)
      (err/throw-odd-map rdr start-line start-column the-map))
    (with-meta
      (if (zero? map-count)
        {}
        (RT/map (to-array the-map)))
      (when start-line
        (merge
         (when-let [file (get-file-name rdr)]
           {:file file})
         {:line start-line
          :column start-column
          :end-line end-line
          :end-column end-column})))))

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
    nil))