Вопрос

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