Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Compiler by
retagged by
(defmacro inspect
  [& body]
  (println (keys &env) (map meta (keys &env)))
  `(do ~@body))

(let [^:1 a 1]
  (let [^:2 a 2]
    (let [^:3 a 3]
      (inspect "hello"))))

;;=> (a) ({:1 true})

The &env form returns a map of {sym LocalBinding} and the symbols on the keys of the map are supposed to be the local symbols, but as we see in the above code, when a local symbol is shadowing another, it seems the map does not contain the shadowing symbol, but instead contains the shadowed symbol. We can see that because it is returning the metadata of the outermost symbol, and not the inner one that is shadowing it.

In my opinion, this is a bug, that said, you can still get at the actual shadowing symbol by calling .-sym on the LocalBinding, in which case you get the inner shadowing symbol and it will have the right metadata.

1 Answer

+1 vote