I want to do something like this for debugging purposes:
(intern 'clojure.core 'doc clojure.repl/doc)
but it is not letting me because the compiler says - cant take value of a macro.
is there another way?
A macro is a function stored in a Var with :macro true
in its metadata map. So, you can
obtain the macro function itself by deref
ing the Var:
@#'doc
use intern
to install a function as a macro by attaching appropriate metadata to the name symbol (see (doc intern)
which promises to transfer any metadata provided in this way to the Var):
(intern 'clojure.core
(with-meta 'doc {:macro true})
@#'clojure.repl/doc)
Using reader metadata is possible too, just remember to put it "inside the quote":
;; attaches metadata to the symbol, which is what we want:
' ^:macro doc
;; attaches metadata to the list structure (quote doc):
^:macro 'doc
^:macro
is shorthand for ^{:macro true}
.
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