Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nested macros in clojurescript

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?

like image 721
emareaf Avatar asked Oct 23 '25 09:10

emareaf


1 Answers

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.

like image 131
dnolen Avatar answered Oct 25 '25 13:10

dnolen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!