#:{} namespaced map

syntaxsince v1.9.183 in clojureEdit

Provide a default namespace for keyword keys in a map.

#:a {1 nil, :b nil, :b/c nil, :_/d nil}
;;=> {1 nil, :a/b nil, :b/c nil, :d nil}

Reader code @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(defn- read-namespaced-map
  [rdr _ opts pending-forms]
  (let [token (read-token rdr :namespaced-map (read-char rdr))]
    (if-let [ns (cond
                  (= token ":")
                  (ns-name *ns*)

                  (= \: (first token))
                  (some-> token (subs 1) parse-symbol second' symbol resolve-ns ns-name)

                  :else
                  (some-> token parse-symbol second'))]

      (let [ch (read-past whitespace? rdr)]
        (if (identical? ch \{)
          (let [items (read-delimited :namespaced-map \} rdr opts pending-forms)]
            (when (odd? (count items))
              (err/throw-odd-map rdr nil nil items))
            (let [keys (take-nth 2 items)
                  vals (take-nth 2 (rest items))]

              (RT/map (to-array (mapcat list (namespace-keys (str ns) keys) vals)))))
          (err/throw-ns-map-no-map rdr token)))
      (err/throw-bad-ns rdr token))))

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