Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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))
like image 273
Matthew H Avatar asked Aug 23 '13 18:08

Matthew H


1 Answers

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.

like image 171
Michał Marczyk Avatar answered Sep 30 '22 07:09

Michał Marczyk