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

0 votes
in ClojureScript by

I have a macro that calls macroexpand inside it's body so it can walk over macroexpanded code for generating it's output.

It works perfectly when called from Clojure but when calling it from ClojureScript the macroexpand call just return its input without doing any macroexpansion.


(defmacro m [form]
  (let [form' (macroexpand form)]
   ;; do something with form'

This looks like a bug to me, what do you think? Any workaround?

Here is a repo that reproduces the issue : https://github.com/jpmonettas/clojurescript-macro-issue


1 Answer

+1 vote

Clojurescript doesn't compile macros. You can put your macro in a Clojure source file and use (:require-macros […]) in your Clojurescript file in the ns declaration.

A good example of this is in Reagent, where the macro is imported at https://github.com/reagent-project/reagent/blob/master/src/reagent/core.cljs#L2 and defined at https://github.com/reagent-project/reagent/blob/master/src/reagent/core.clj#L4 .