Skip to content

Instantly share code, notes, and snippets.

@akovantsev
Last active July 30, 2020 10:25
Show Gist options
  • Save akovantsev/b9c66d071af713c045290087c73a927d to your computer and use it in GitHub Desktop.
Save akovantsev/b9c66d071af713c045290087c73a927d to your computer and use it in GitHub Desktop.
(defmacro locals-map [& [env]]
;; https://gist.github.com/noisesmith/3490f2d3ed98e294e033b002bc2de178
(let [ks (->> (or env &env)
keys
(remove #{'_})
(remove #(-> % name (str/includes? "__"))))]
(zipmap (map name ks) ks)))
(defmacro pp-locals []
`(clojure.pprint/pprint
;(reduce-kv
; #(assoc %1 (symbol %2) %3)
; {}
(locals-map ~&env)))
(let [x 1
{:keys [y]} {:y 2}
_ (pp-locals)
{z :zz} {:zz x}]
_ (pp-locals))
; {"x" 1, "y" 2}
; {"x" 1, "y" 2, "z" 1}
; => nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment