Created
October 23, 2012 16:41
-
-
Save amalloy/3939975 to your computer and use it in GitHub Desktop.
This file contains 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 using "ns can be either a symbol designating a namespace, or | |
a list like (ns :only [a b c])." | |
[ns & body] | |
(let [[ns vars] (if (sequential? ns) | |
[(first ns) (nth ns 2)] ;; skip the :only | |
[ns (keys (ns-publics (find-ns ns)))])] | |
`(symbol-macrolet [~@(for [var vars, | |
clause [var `(quote ~(symbol (name ns) (name var)))]] | |
clause)] | |
~@body))) | |
user> (using [clojure.set :only [rename-keys]] | |
(rename-keys {:a 1} {:a :b})) | |
{:a :b} | |
user> (using clojure.set | |
(rename-keys {:a 1} {:a :b})) | |
{:a :b} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment