Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em><strong>'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?'</em></strong></p> <p>What is wrong is that the macro is attempting to do something called 'symbol capture': it is trying to define a symbol that may end up overwriting an already existing symbol in the target namespace, and clojure is trying to protect you from the bugs associated with symbol capture.</p> <p>If you are convinced that what you need is symbol capture then doing what Arthur Ulfeldt suggests above is what you need (using the unquote quote combination ~'my-macro)</p> <p>But my recommendation to you would be to go with a variation of your initial solution and make explicit the fact that your macro will define a variable in the current namespace:</p> <pre><code>(ns foo) (defmacro create-my-macro [macroName] `(defmacro ~macroName [] `1)) </code></pre> <p>an invocation to your macro would look like:</p> <pre><code>(create-my-macro mymacro) </code></pre> <p>that would create a macro called 'mymacro which could then be invoked as follows:</p> <pre><code>(mymacro) ;; would return 1 </code></pre> <p><em><strong>'Also, why doesn't it fail when the macro-generating-macro is called from the same namespace?'</em></strong></p> <p>not sure about this one but my guess is that as you are defining a symbol in the same namespace where the macro exist then it is assumed that you know which symbols are already in use and are responsible for not overwriting (capturing) symbols already used unintentionally. Whereas in the case of the invocation from a different namespace the symbol capture (if allowed) would be a surprising side effect to you. Again, this is just my guess.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      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