Skip to content

Instantly share code, notes, and snippets.

@amalloy amalloy/gist:3939975
Created Oct 23, 2012

Embed
What would you like to do?
(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
You can’t perform that action at this time.