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