Skip to content

Instantly share code, notes, and snippets.

@noisesmith
Last active January 11, 2017 20:39
Show Gist options
  • Save noisesmith/3448f0494a81bbb0adebb66b57f5e9e0 to your computer and use it in GitHub Desktop.
Save noisesmith/3448f0494a81bbb0adebb66b57f5e9e0 to your computer and use it in GitHub Desktop.
use all non-macros from target ns in local scope
phoenix.core=> (user/with-use user (+ 1 1))
2
phoenix.core=> (macroexpand-1 '(user/with-use user (+ 1 1)))
(clojure.core/let [help user/help find-name user/find-name non-macros user/non-macros src-dir user/src-dir exercise-coverage user/exercise-coverage apropos-better user/apropos-better] (+ 1 1))
(defn non-macros
[target-ns]
(map key
(remove #(:macro (meta (val %)))
(ns-publics target-ns))))
(defmacro with-use
[target-ns & body]
`(let ~(into []
(mapcat (juxt identity (fn [s] (symbol (name target-ns) (name s))))
(non-macros target-ns)))
~@body))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment