syntax | since v0.0-1853 | in clojure | in edn | Edit |
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)Creates a map. Must contain pairs of key-values. Keys and values can be any type.
{:foo 1 :bar 2}
;;=> {:foo 1, :bar 2}
Use any value as a key:
(def m {[1 2] 3})
(get m [1 2])
;;=> 3
(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})))))
(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))