Skip to content

Instantly share code, notes, and snippets.

@vvvvalvalval
Created July 25, 2015 14:16
Show Gist options
  • Save vvvvalvalval/b2f3cebab5f6cc48150b to your computer and use it in GitHub Desktop.
Save vvvvalvalval/b2f3cebab5f6cc48150b to your computer and use it in GitHub Desktop.
Map restructuring
(defmacro m:p "Makes a map from a list of symbols, using the symbol names to create keyword keys.
---
(let [a 1 b 2 c \"3\"]
(m:p a b c))
=> {:a 1, :b 2, :c \"3\"}
" [& syms]
(reduce (fn [m sym]
(assert (symbol? sym) "m:p only accepts symbols")
(assoc m (keyword (name sym)) sym))
{} syms))
(comment
(let [a 1 b :two c "three"]
(m:p a b c))
=> {:a 1, :b :two, :c "three"}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment