Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by
I have defined a macro in a .cljc file:

(defmacro ->map
  "(->map a b) ;;=> {:a a :b b}"
  [& symbols]
  (assert (every? symbol? symbols))
    ~@(interleave (map keyword symbols) symbols)))

Sometimes (but not always) I would see an error in the browser logs:

router.cljc:203 Uncaught Error: Assert failed: (every? symbol? symbols)
    at Function.dre.coll.__GT_map.cljs$core$IFn$_invoke$arity$variadic (coll.cljc:563)
    at dre$coll$__GT_map (coll.cljc:560)
    at events.cljs:64

Why is a compile time macro ending up as a run time function in the target JS? Quite a surprise. After a discussion on Slack this turned out to be related to self-hosted ClojureScript. The conversation in Slack is recorded in the attachment slack.txt.

The library https://github.com/cgrand/macrovich turned out to have the solution for me.

It would be helpful if the compiler did not generate a run-time function from a macro in non-self hosted mode, or at least emit a warning.

1 Answer

0 votes
Reference: https://clojure.atlassian.net/browse/CLJS-2636 (reported by borkdude)