Sunil S Nandihalli <sunil.nandiha...@gmail.com> writes: > I really like the &env. It has saved a lot of tedious work a couple of > times .. but I have only found use for the keys of the map that gets > passed like in the following example.
> I don't understand what the val part of the map contains? I have > failed at attempts to figuring it out.. Can somebody tell me what the > val part contains and how one could use it? It contains a LocalBindings object which the compiler uses internally to keep track of a local binding. Note that unlike the keys, the values of &env are not a stable API, they're implementation details and may well change. When he added &env I think Rich said he'd look at giving the values of &env a proper API as part of the future Clojure in Clojure compiler. But you can poke at them like this: (defmacro foo [] (def lb (first (vals &env)))) (let [a (+ 1 3)] (foo)) (.sym lb) ;; a (.idx lb) ;; 1 (.name lb) ;; "a" (.isArg lb) ;; false (.canBeCleared lb) ;; true (.init lb) ;; #<StaticMethodExpr ;; clojure.lang.compiler$staticmethode...@1a9d267d> (.args (.init lb)) ;; [#<ConstantExpr clojure.lang.compiler$constante...@51d2bb9f> ;; #<ConstantExpr clojure.lang.compiler$constante...@621bedb0>] If you're using Emacs + SLIME, the SLIME inspector is quite useful for exploring unknown values. After evaling the first two forms above, put the cursor over "lb" and press C-c I (note that's shift + i). You'll get something like this: clojure.lang.compiler$localbind...@25de152f -------------------- Type: class clojure.lang.Compiler$LocalBinding Value: clojure.lang.compiler$localbind...@25de152f --- Fields: sym: a tag: init: clojure.lang.compiler$staticmethode...@1a9d267d idx: 1 name: a isArg: false clearPathRoot: clojure.lang.compiler$pathn...@1740d415 canBeCleared: true You can then press enter on any of the field values or class names to get more detail about them. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en