如何编写一个函数来解决词法环境中的符号?
(let [foo some-var]
(let [sym 'foo]
(resolve-sym sym)))
Run Code Online (Sandbox Code Playgroud)
我想得到'foo绑定的var.
我不完全确定为什么我想要这样的东西,但看起来它肯定可以做到。来自http://clojuredocs.org/circumspec/circumspec.should/local-bindings
(defmacro local-bindings
"Produces a map of the names of local bindings to their values.
For now, strip out gensymed locals. TODO: use 1.2 feature."
[]
(let [symbols (remove #(.contains (str %) "_")
(map key @clojure.lang.Compiler/LOCAL_ENV))]
(zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols)))
(let [foo 1 bar 2]
(local-bindings))
=> {foo 1, bar 2}
Run Code Online (Sandbox Code Playgroud)