clojure - resolve a symbol inside let

clojure, lisp

Solution

I am not completely sure why I want something like this, but looks like it can certainly be done. from 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}

Problem

How do I write a function to resolve a symbol in a lexical environment? ``` (let [foo some-var] (let [sym 'foo] (resolve-sym sym))) ``` I want to get the var that 'foo is bound to.

Original source