Fork me on GitHub
AJ Jaro15:10:40

I’d like to be able to print out the docstring for a macro that used in CLJS. The macro is defined in a CLJ file then required in a CLJS file via require-macros. I’m working towards documenting some of our work standards and having the docstring available to present would be super helpful. In CLJ, I would normally use (:doc (meta #'macro-here)), but that doesn’t seem to work the same when requiring macros. Is there a different way I should be solving this?


(defmacro macro-doc [macro-name] 
  (:doc (meta (var macro-name))))


there might be a better way, but you can pull it out in another macro since that runs in the CLJ scope

AJ Jaro22:10:26

@U3JH98J4R Are you suggesting writing a CLJ macro? That might be useful in a number of places for us anyway

AJ Jaro22:11:15

@U3JH98J4R Thanks. I am struggling with the details here. I wrote the macro like this and used refer-macros, but I’m getting the error that it can’t resolve the passed in var

(defmacro docstring [fn]
  `(:doc (meta (var ~fn))))
(docstring defn) Unable to resolve var: defn in this context


Get rid of the ` and the ~


When you return a quoted list, that's what gets used as the CLJS code


This whole process needs to run in CLJ, and the thing that gets inserted into CLJS as code would just be the literal string

AJ Jaro22:11:31

Ok, there’s more thinking I need to do here because it worked successfully in a CLJ REPL without those changes


That's because the var exists in CLJ


In CLJ it can be just a regular function