Last active
July 30, 2020 10:25
-
-
Save akovantsev/b9c66d071af713c045290087c73a927d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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