Hi everybody!,Does anybody knows why this macro
(defmacro tester [form]
(println (macroexpand form))
nil)
When used from clojure :
(tester (let [a 5] a))
;; prints
(let* [a 5] a)
But when used from clojurescript :
(tester (let [a 5] a))
;; prints
(let [a 5] a)
So the same macro doesn’t do the same, macroexpand doesn’t work at macro level when the cljs compiler calls it
didibus
September 9, 2020, 2:05am
2
There is no macroexpand
in ClojureScript. ClojureScript cannot expand macros, only Clojure can.
And in your case, I’m guessing maybe your macro isn’t defined properly for ClojureScript. I forgot the rules, but it is a bit tricky. The macro has to be in a .clj
file, and in ClojureScript you need to call require-macro
.
Sorry, maybe I didn’t specified all the details.
This is a normal Clojure macro defined in a macros.clj file.
So it goes something like this:
In macros.clj :
(ns project.macros)
(defmacro m [form]
(let [form2 (macroexpand form)]
;; do something with form2
))
In test.cljs :
(ns project.test
(:require-macros [project.macros :refer [m]])
(println (and 1 2))
So if I use that same macro from a clojure project, form2 gets bind to
(let* ... (if* ...))
While when using it from clojurescript form2 gets bind to
(and 1 2)
Shouldn’t the macro be expanding the same, since it is compile time and clojure world?
system
Closed
March 10, 2021, 11:34pm
4
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.