Thanks Nicola and Justin,

syntax quote works, if the call of the macro is explicitely given in the 
code.
In the real situation, whereI had the problem, the form which contains the 
macro call is generated on the fly by a function.

But your hint helps nethertheless:
I bind the namespace to that in which the macro is defined:

(ns m
  (:gen-class))

(defmacro mx
  [x]
  (list 'y))

(defn -main []
  (binding[*ns* (find-ns 'm)]
    (println (macroexpand-1 `(mx P))))
  (println (macroexpand-1 '(and P Q))))

 

Am Donnerstag, 15. Februar 2018 12:52:39 UTC+1 schrieb Justin Smith:
>
> To elaborate on Nicola's correct answer, when -main is run from outside 
> its namespace, the binding of mx comes from the current environment (which 
> doesn't see a macro, and likely has no binding for mx). If you use ` in 
> -main, the currently visible binding is properly namespace qualified so 
> that it expands when called from outside the namespace.
>
> On Thu, Feb 15, 2018, 03:12 Nicola Mometto <brob...@gmail.com 
> <javascript:>> wrote:
>
>> Use ` instead of '
>>
>>
>> On 15 Feb 2018, at 08:45, 'Burt' via Clojure <clo...@googlegroups.com 
>> <javascript:>> wrote:
>>
>> Here is something strange, and I don't see why!
>> Can anybody help?
>>
>> This is the code in m.clj
>>
>> (ns m
>>   (:gen-class))
>>
>> (defmacro mx
>>   [x]
>>   (list 'y))
>>
>> (defn -main []
>>   (println (macroexpand-1 '(mx P)))
>>   (println (macroexpand-1 '(and P Q))))
>>
>>
>> 1 When i load the namespace into a REPL and invoke (-main)
>>
>> the result is (as expected):
>>
>>
>> (y)
>> (clojure.core/let [and__5236__auto__ P] (if and__5236__auto__ 
>> (clojure.core/and Q) and__5236__auto__))
>> => nil
>>
>>
>> 2 When I make an uberjar with leiningen (in IntelliJ with cursive) and run 
>> the jar
>>
>> the result is (not as expected):
>>
>>
>> (mx P)
>> (clojure.core/let [and__5236__auto__ P] (if and__5236__auto__ 
>> (clojure.core/and Q) and__5236__auto__))
>>
>>
>> In the second case the macro mx is not expanded and I have no idea why this 
>> is the case.
>>
>>
>> Kind regards,
>>
>> Burt
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> <javascript:>
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com <javascript:>
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> <javascript:>
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com <javascript:>
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to