Note that there are some explanatory texts on larger screens.

plurals
  1. POmacro-producing macro invoked from another namespace :: Can't refer to qualified var that doesn't exist
    primarykey
    data
    text
    <p>I have a macro-producing macro which I am trying to call from another namespace and it fails with "Can't refer to qualified var that doesn't exist".</p> <p>I managed to reproduce it in the following code which is the simplest possible that exemplifies the problem. I also found a workaround, however I would like to understand the cause of the problem and whether some better solution exists.</p> <h1>problem</h1> <h3> file foo.clj </h3> <pre><code>(ns foo) (defmacro create-my-macro [] `(defmacro my-macro [] nil)) </code></pre> <h3> file boo.clj </h3> <pre><code>(ns boo (:use [foo])) (create-my-macro) </code></pre> <p>The above code when executed with:</p> <pre><code>java -cp clojure-1.4.0.jar clojure.main boo.clj </code></pre> <p>... fails with:</p> <pre><code>Exception in thread "main" java.lang.RuntimeException: Can't refer to qualified var that doesn't exist, compiling:(...boo.clj:2) </code></pre> <h1>workaround</h1> <p>For some reason, when the macro-producing macro is enhanced to accept a name for the macro to be created as a parameter, there is no failure.</p> <h3>file foo.clj</h3> <pre><code>(ns foo) (defmacro create-my-macro [macroName] (let [the-macroName (symbol macroName)] `(defmacro ~the-macroName [] 1))) </code></pre> <h3>file boo.clj</h3> <pre><code>(ns boo (:use [foo])) (create-my-macro "foo") (println (foo)) </code></pre> <p>Running file boo.clj as above outputs a clean "1" on the console without any complains.</p> <p>So, what was wrong in the first case and is there another way to fix it changing the macro-producing-macro to accept a name for the macro to be produced as a parameter? Also, why doesn't it fail when the macro-generating-macro is called from the same namespace?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload