-
-
Save athos/f3d4d7d572c9978e2b70 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
(ns local-env | |
(:use [clojure.contrib.def :only (defvar-)]) | |
(:use [clojure.contrib.macro-utils :only (mexpand-all symbol-macrolet)])) | |
(defvar- *local-envs* {}) | |
(defmacro let-env [env-name & body] | |
(binding [*local-envs* (assoc *local-envs* env-name &env)] | |
`(let [~env-name ~(into {} (for [x (keys &env)] `['~x ~x]))] | |
~(mexpand-all `(do ~@body))))) | |
(defmacro with-env [env-name & body] | |
(let [env (*local-envs* env-name)] | |
(mexpand-all | |
`(symbol-macrolet ~(vec (mapcat (fn [name] | |
`[~name (~env-name '~name)]) | |
(keys env))) | |
~@body)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment