Map literal syntax - #: and #::

#: map literal macro for Clojure hash-maps adds a given namespace to all the keywords contained in the hash-map.

#:: map literal macro for keyword auto-resolve adds the current fully qualified namespace to all the keywords in the hash-map

Require clojure spec in the namepace of page.

(ns practicalli.clojure
  (:require [clojure.spec.alpha :as spec]))

In this example the keys in the map are unqualified.

{:simplyfying      []
    :keyword-names    []
    :with-autoresolve []
    :map-literal      []}

Qualifying keys with auto-resolve

Using the map literal macro for auto-resolve instructs Clojure to treat all keys in the map as qualified to the current namespace

The following hash-map has the map literal macro.

#::{:simplyfying      []
    :keyword-names    []
    :with-autoresolve []
    :map-literal      []}

This is the same as explicitly writing out the fully qualified domain for each key in the map.

However, if we move the map to another namespace, then the explicit namespaces would need to be updated.

{:practicalli.clojure/simplyfying      []
 :practicalli.clojure/keyword-names    []
 :practicalli.clojure/with-autoresolve []
 :practicalli.clojure/map-literal      []}

Qualifying keywords with a specific name

Rather than take the name from the current namespace, an explicit name can be added to all the keys in the map

#:practicalli.naming {:simplyfying      []
                      :keyword-names    []
                      :with-autoresolve []
                      :map-literal      []}

This is the same as explicitly writing that name in front of each of the keywords in the map.

# {:practicalli.naming/simplyfying      []
   :practicalli.naming/keyword-names    []
   :practicalli.naming/with-autoresolve []
   :practicalli.naming/map-literal      []}

Map literals are relevant to Entity maps with spec.

results matching ""

    No results matching ""