I'd like to construct a ClojureScript macro (executed/compiled via Clojure) that informs it's construction of a return form based on the static, compile-time metadata of a ClojureScript var argument.
I understand it is possible to access compile-time, static var metadata from ClojureScript code (using (meta (var varsym))
; see this post). But is this data accessible to the compilation process in such a way that we could access it from a macro?
Here's a rough sketch of what I'd like to do (and the question is really how you'd write get-meta-for-varsym
below):
;; executed/compiled in clj, targeting cljs
(defmacro themacro
[varsym & args]
(let [var-meta (get-meta-for-varsym varsym)
return-form (compile-return-form-from-metadata var-meta args)]
return-form))
For this you have to use the Clojurescript analyzer:
(ns your-macros
(:require [cljs.analyzer :as cljs]))
(defmacro var-data
[sym]
(cljs/resolve-var &env sym))
Then in your clojurescript file:
(ns your-cljs)
(def ^{:foo :bar} xxy {})
(var-data xxy)
The meta data will be in :meta
key of the map.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With