Browse files

degeneralize env passing

  • Loading branch information...
1 parent 99da018 commit 7be229b00d6c04de5870184069b11422fa30268f @hiredman committed Nov 19, 2011
Showing with 14 additions and 18 deletions.
  1. +14 −18 src/syntax_quote/core.clj
@@ -1,45 +1,41 @@
(ns syntax-quote.core)
-(defmacro env-map []
- (into {} (for [[k _] &env] [(keyword (name k)) k])))
(defmacro let-smacros
"macros: a map of symbols to what they should be replaced with in the body"
[macros & body]
- (let [transform (fn [env body]
+ (let [transform (fn [transform-coll body]
(if (coll? body)
- ((:transform-coll env) env body)
+ (transform-coll body)
(if (symbol? body)
(get macros body body)
- expand (fn [env the-seq]
+ expand (fn [the-seq]
(let [m (macroexpand the-seq)]
(if (= m the-seq)
- (recur env m))))
- transform-seq (fn [env the-seq]
- (map (partial transform env) the-seq))
- transform-coll (fn [env coll]
+ (recur m))))
+ transform-seq (fn [transform-coll the-seq]
+ (map (partial transform transform-coll) the-seq))
+ transform-coll (fn transform-coll [coll]
(if (seq? coll)
- (transform-seq env (expand env coll))
+ (transform-seq transform-coll (expand coll))
(if (set? coll)
- (set (transform-seq env (seq coll)))
+ (set (transform-seq transform-coll (seq coll)))
(if (vector? coll)
- (vec (transform-seq env (seq coll)))
+ (vec (transform-seq transform-coll (seq coll)))
(if (map? coll)
- (transform-seq env (keys coll))
- (transform-seq env (vals coll)))
- coll)))))
- env (env-map)]
+ (transform-seq transform-coll (keys coll))
+ (transform-seq transform-coll (vals coll)))
+ coll)))))]
(cons 'do
((fn map [fun the-seq]
(if (seq the-seq)
(cons (fun (first the-seq))
(map fun (rest the-seq)))))
- env)
+ transform-coll)
(def ^{:dynamic true} *symbol-table*)

0 comments on commit 7be229b

Please sign in to comment.