#::{} namespaced map

syntaxsince v1.9.183 in clojureEdit

Provide a default namespace for keyword keys in a map, using an alias.

  • #:: {:a 1} => {:current-ns/a 1}
  • #::s {:a 1} => {:aliased-ns/a 1}

Reader code @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(defn- read-namespaced-map
  [rdr _ opts pending-forms]
  (let [[start-line start-column] (starting-line-col-info rdr)
        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)
                [end-line end-column] (ending-line-col-info rdr)]
            (when (odd? (count items))
              (err/throw-odd-map rdr nil nil items))
            (let [keys (take-nth 2 items)
                  vals (take-nth 2 (rest items))]
              (with-meta
                (RT/map (to-array (mapcat list (namespace-keys (str ns) keys) vals)))
                (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})))))
          (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))