Fork me on GitHub
#clojurescript
<
2024-04-22
>
hifumi12322:04:16

Suppose I am writing a library that supports Clojure and ClojureScript. The library exports a macro. Most ClojureScript users are not using self-hosted ClojureScript, so it makes sense to define macros in a cljc file by keeping defmacro forms in Clojure. However, in the case of self-hosted ClojureScript, we want these macros, too. So rather than

#?(:clj (defmacro ...))
we would want
(defmacro ...)
directly in a CLJC file. Is there harm in doing this when consuming the library from non-self-hosted CLJS? I’ve always had the habit of avoiding defmacro forms in CLJS code entirely, so I am not sure what the behavior is.

thheller23:04:25

none of those are required to make self hosted macros

thheller23:04:55

and yes, the answer is to just use defmacro as-is. it just works and doesn't hurt not self-hosted builds in any way

thheller23:04:25

(shadow-cljs automatically elides defmacro from CLJS compilation anyway)

👍 1