I'm working in clojurescript, where ns-interns
is a macro.
I'm trying to write a macro that gets information about the internal bindings in a namespace, but I'm not able to manipulate the bindings at compile time.
(defmacro my-macro [namespace]
(let [mappings (ns-interns namespace)]
; do stuff
))
(my-macro 'mylib.hi)
The trouble is that the above fails because the ns-interns
macro think it's processing the symbol namespace
, and not the namespace I pass into my-macro
.
I can try
[mappings `(ns-interns ~namespace)]
, but then I can't expand the macro at compile-time into a map that I can use to generate code -- the only thing I can do is "print" it in the generated code. I tried using macroexpand
and macroexpand-all
, but they did not work for me -- I couldn't use them to get the results of ns-interns
for use in my macro.
However, macros can be expanded, since the below will work if I hard-code the namespace symbol. The trouble comes because I want to pass the outer macro's argument into an inner macro. What's the right way to solve approach this, where I want to get and manipulate the vars of a namespace at compile-time in Clojurescript?
(defmacro my-macro [namespace]
(let [mappings (ns-interns 'mylib.hi)]
; do stuff
)
)