hash-map*
, from Chris Houser, lets you build a Clojure map similarly to the built-in hash-map
. The value-add here is that you can refer to earlier key-value pairs when building up the map.
(defmacro hash-map* [sym & body]
`(let [~sym {}
~@(mapcat (fn [[k v]] [sym `(assoc ~sym ~k ~v)]) (partition 2 body))]
~sym))
This sort of reminds me of let
, where you can bind new values based on previous ones.