Skip to content

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 namespace definitionλ︎

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

In this example the keys in the map are unqualified.

{:simplifying      []
    :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.

#::{:simplifying      []
    :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/simplifying      []
 :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 {:simplifying      []
                      :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/simplifying      []
   :practicalli.naming/keyword-names    []
   :practicalli.naming/with-autoresolve []
   :practicalli.naming/map-literal      []}

Map literals are relevant to Entity maps with spec.