I have the following code in a clj (clojure) namespace.
(ns project.clojure.clojurescript-macros)
(def trace-history (atom []))
; hmm, you could run out of memory on recursive functions here?
; Fortunately functions aren't actually recursive in clojure. :]
(defmacro push-args [name args]
`(swap! trace-history
(fn [stack#]
(conj stack# [~name (zipmap ~(vec (map str args)) ~args)]))))
(push-args :hello [:a :b :c])
within another cljs (clojurescript) namespace, I have the following
(ns project.clojurescript.user
(:require-macros [project.clojure.clojurescript-macros :as c]))
(c/push-args :hello [:a :b :c])
I compile my clojurescript code, and open it in my browser, Unfortunately, I get the following error.
Uncaught TypeError: Cannot read property 'trace_history' of undefined main.js:22348
(anonymous function) main.js:22348
Looking at line 22348 in my compiled clojurescipt code, I see the following.
cljs.core.swap_BANG_.call(null, project.clojure.trace_history, function(stack__6402__auto__) {
return cljs.core.conj.call(null, stack__6402__auto__,
cljs.core.PersistentVector.fromArray(["\ufdd0'hello",
cljs.core.zipmap.call(null,
cljs.core.PersistentVector.fromArray([":a", ":b", ":c"], true),
cljs.core.PersistentVector.fromArray(["\ufdd0'a", "\ufdd0'b", "\ufdd0'c"],
true))],
true))
});
The problem is that project.clojure.trace_history has not been defined anywhere in main.js . I understand what is wrong, but I am unsure as to how I might fix it. I have tried out other solutions, such as putting trace-history in a shared clojure file and putting trace history in a cljs file itself. None seem to work. Given that I want to have a shared global atom between all compilations of this macro, how can I do so in Clojurescript?