Skip to content

Instantly share code, notes, and snippets.

@syou6162
Created August 17, 2012 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save syou6162/3378163 to your computer and use it in GitHub Desktop.
Save syou6162/3378163 to your computer and use it in GitHub Desktop.
(defmacro hash-map-by-names [names]
`(let [ks# (map keyword '~(keys &env))
vs# (list ~@(keys &env))
names# (map keyword '~names)]
(select-keys (zipmap ks# vs#) names#)))
(let [x 1
y 2
z 3]
(hash-map-by-names [x y])) ; {:y 2, :x 1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment