In a file i define these 2 macros:

(ns macros)

(defmacro foo [a]
  `(+ ~a 2))

(defmacro bar [a]
  `(* 2 (foo ~a)))

In clojure both macros work as intended.

In clojurescript only the macro "foo" works, "bar" produces this error:

"Error evaluating:" (bar 0) :as "(2 * macros.foo.call(null,0));\n"
org.mozilla.javascript.EcmaError: ReferenceError: "macros" is not defined. (<cljs repl>#4)
    at <cljs repl>:4 (anonymous)
    at <cljs repl>:4

It seems that here the "foo" macro gets not expanded but interpreted as a function call.

Ist this a bug in clojurescript or did i something wrong?

有帮助吗?

解决方案

I believe the issue you're seeing here is due to the single element namespace for the macros file. If you change it to util.macros and put in the proper place on the classpath to account for that, it works.

Probably a bug given it works without issue in Clojure.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top