Skip to content

Instantly share code, notes, and snippets.

@darkleaf
Created September 3, 2019 16:17
Show Gist options
  • Save darkleaf/327ccf2a14ea9ae9ff1a6ff1bfed2ebb to your computer and use it in GitHub Desktop.
Save darkleaf/327ccf2a14ea9ae9ff1a6ff1bfed2ebb to your computer and use it in GitHub Desktop.
(ns foo
(:import
[clojure.lang Compiler Compiler$C]))
(defn get-closure-names* [form env]
(let [ex (with-bindings {Compiler/LOCAL_ENV env}
(Compiler/analyze Compiler$C/EXPRESSION form))
closes (.closes ex)]
(->> closes
(keys) ;; у них ключи и значения совпадают
(map #(.-sym %)))))
(defmacro get-closure-names [form]
`(quote ~(get-closure-names* form &env)))
(let [a 1
b 2]
(get-closure-names (fn [x] [a]))) ;;=> '(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment