I'm discussing an issue with @ptaoussanis about macros and making them also work for scittle.
Scittle doesn't read :clj branches but he did put his defmacro in :clj branch, which is probably good practice. What's the downside of not wrapping macros in a reader conditional in CLJS?
I have a library that just declares a macro top level below. It seems to work fine for CLJ, CLJS, nbb, scittle, etc. Perhaps the only downside is that for non-bootstrap targets you'll also get some garbage at runtime? Maybe CLJS non-bootstrap could just ignore defmacro if that is the only downside?
https://github.com/borkdude/deflet/blob/main/src/borkdude/deflet.cljc
I don't know if it really matters much dead code elimination and all
Do you think it will or won't be eliminated? I can do a test of course. But is that the only problem with leaving them top level without reader conditional?
If your code doesn't reference it assume it will be eliminated
how would one (accidentally maybe) reference the runtime macro? only by referencing it in non-call position I guess? assuming one has a refer like this:
(:require-macros [borkdude.deflet :refer [deflet]])that's not how tree-shaking works - you need to actually use it
it's irrelevant what you require etc.
assuming the thing you're requiring isn't running arbitrary side effects beyond declaring vars
most real programs have some entry point - Closure will figure it out from there
I understand that :). but if you don't include this:
(:require-macros [borkdude.deflet :refer [deflet]])
and you do write:
(defmacro deflet ...)
and call (deflet ...) you probably end up referencing the runtime macrojust trying to figure out where top level macro in cljc can go wrong for users. I know I've had a case of this ten years ago, but maybe I did accidentally use it in a non-call position or so
yes you can call deflet and it will be a function
FWIW in shadow-cljs during regular CLJS compilation it just https://github.com/thheller/shadow-cljs/blob/c454433fbb06087b559f4c75dca58bf904563eba/src/main/shadow/build/compiler.clj#L545-L555 defmacro and doesn't even compile it, so DCE isn't even a question. very minor tweak.
Thatβs great, thanks