Skip to content

Instantly share code, notes, and snippets.

@AlexBaranosky
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexBaranosky/9756397 to your computer and use it in GitHub Desktop.
Save AlexBaranosky/9756397 to your computer and use it in GitHub Desktop.
(defmacro let-map
"Creates a hash-map which can refer to the symbols of the names of the keys
declared above."
[& kvs]
(assert (even? (count kvs)))
(let [ks (take-nth 2 kvs)
sym-ks (map (comp symbol name) ks)
vs (take-nth 2 (rest kvs))]
`(let ~(vec (interleave sym-ks vs))
~(apply hash-map (interleave ks sym-ks)))))
(comment
(let-map
:a 1
:b a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment