On Sat, Oct 3, 2015 at 5:24 PM, gianluca torta <giato...@gmail.com> wrote:

> Hi,
>
> the behavior you describe is not specific to macros, but is due to the use
> of aliases
>
> after:
> (require '[foo.bar :as b])
>
> this will give you false:
> (= 'foo.bar/x (first '(b/x)))
>
> while this will give you true:
> (= 'foo.bar/x (first '(foo.bar/x)))
>
> one way to solve it, is comparing the resolved vars instead of the names:
> (= (resolve 'foo.bar/x) (resolve (first '(b/x))))
> ;=>true
> (= (resolve 'foo.bar/x) (resolve (first '(foo.bar/x))))
> ;=>true
>
>
Yes, your solution works, but only on clojure. ClojureScript doesn't have
`resolve`. It there any portable solution?

Thanks!

Andrey


> hth,
> Gianluca
>
>
>
> On Saturday, October 3, 2015 at 3:03:49 PM UTC+2, Andrey Antukh wrote:
>
>> Hi!
>>
>> I have a little trouble writing a macro because I'm getting unexpected
>> (for me) behavior.
>>
>> Let see some code:
>>
>> (ns foo.bar)
>>
>> (defn debug
>>   [x]
>>   (println "debug:" x)
>>   x)
>>
>> (defn debug-expr?
>>   [expr]
>>   (and (seq? expr)
>>        (symbol? (first expr))
>>        *(= 'foo.bar/debug  (first expr))*))
>>
>> (defmacro without-debug
>>   [& body]
>>   (let [body' (reduce (fn [acc v]
>>                         (if (debug-expr? v)
>>                           (conj acc (second v))
>>                           (conj acc v)))
>>                       [] body)]
>>     `(do
>>        ~@body')))
>>
>>
>> And then I use it from other namespace:
>>
>> (ns foo.baz)
>>
>> (require '[foo.bar :as b])
>>
>> (macroexpand '(b/without-debug (b/debug 3)))
>> ;; => (do (b/debug 3))
>>
>> (macroexpand '(b/without-debug (foo.bar/debug 3)))
>> ;; =>(do 3)
>>
>> I expect that the both expressions will evaluate to the same result, but
>> is not. Seems that symbols inside macros are not fully qualified. It there
>> any way to get them fully qualified? I'm missing something?
>>
>> Any help is welcome!
>>
>> Thank you very much.
>>
>> Andrey
>> --
>> Andrey Antukh - Андрей Антух - <ni...@niwi.nz>
>> http://www.niwi.nz
>> https://github.com/niwinz
>>
> --
> 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.
>



-- 
Andrey Antukh - Андрей Антух - <n...@niwi.nz>
http://www.niwi.nz
https://github.com/niwinz

-- 
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