Created
July 25, 2015 14:16
-
-
Save vvvvalvalval/b2f3cebab5f6cc48150b to your computer and use it in GitHub Desktop.
Map restructuring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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