Matthew H
Matthew H

Reputation: 5879

ClojureScript macro error: "Can't def ns-qualified name"

What's causing this error?

(defmacro defn+
  [name & stmts]
  `(defn htrhrthtrh ~@stmts)) 

(defn+ init
  []
  (js/alert "hi"))

--

java.lang.AssertionError: Assert failed: Can't def ns-qualified name
(not (namespace sym))

Upvotes: 5

Views: 366

Answers (1)

Michał Marczyk
Michał Marczyk

Reputation: 84331

htrhrthtrh gets namespace-qualified by syntax-quote in the output, so the result looks like

(defn some.namespace/htrhrthtrh [] (js/alert "hi"))

which is incorrect, as explained in the exception message.

Presumably you'll want to use ~name in place of htrhrthtrh to include the name argument to defn+ in the output; this, or anything along similar lines, would fix the problem. To hard-wire this exact name you'd have to say ~'htrhrthtrh.

Upvotes: 7

Related Questions