Open myguidingstar-zz opened 10 years ago
(defmacro binding [bindings & body]
(let [bindings (partition 2 bindings)
;; todo: unique symbol
ks (map #(-> % first name
((fn [s] (keyword s)))) bindings)
vs (map second bindings)
binding-map (zipmap ks vs)]
`(let [binding-map ~binding-map]
(.call (fn [] ~@body)
binding-map))))
(binding [*a* 2] (foo))
Cl2> (def a 1) ==> nil Cl2> a ==> 1 Cl2> (defn foo [] this.a) ==> nil Cl2> (foo) ==> 1 Cl2> (.call foo {:a 2}) ==> 2