clojurescript

2026-04-28T14:38:35.112169Z

in clojure, i can test if macro expansion fails by writing (is (thrown? (eval (foo 1 2 3))))`. is there a way to do that in clojurescript?

✅ 1
p-himik 2026-04-28T14:41:56.577429Z

Are you talking about self-hosted CLJS? Because otherwise CLJS macros are just CLJ code that gets run during compilation. Apart from that, that thrown? tests not just macro expansion but also whether or not the expanded code works. In CLJS in general, macro expansion and code running are two separate stages, run on different platforms. While it's still possible to check stuff like this, it's definitely not built-in and I can't imagine for it to be trivial to do.

2026-04-28T14:42:24.727569Z

cool, that's what i thought

2026-04-28T14:42:38.447279Z

i'm not talking self-hosted, just plain clojurescript

seancorfield 2026-04-28T15:02:02.170269Z

Why not macro-expand instead of eval?

2026-04-28T15:04:31.949319Z

in clj, it's just what i chose when i wrote the tests. in cljs, neither macro-expand nor eval exist

seancorfield 2026-04-28T15:05:25.910279Z

Oh... Hmm, yeah, of course, because macros are already expanded before runtime 😐

p-himik 2026-04-28T15:05:48.521929Z

Also, in CLJ it wouldn't test for "the macro works". It would catch only failures where the expansion itself is broken, but eval also catches when the result is broken. A macro can produce garbage like (1) without throwing.

seancorfield 2026-04-28T15:06:32.983489Z

I haven't written enough cljs for my brain to have internalized the rules... Yeah, I guess it depends what you mean by "test if macro expansion fails" 🙂