Aaron Iba
Aaron Iba

Reputation: 625

Clojure: Qualified keyword inside a macro that resolves in caller's namespace?

Is it possible to have a qualified keyword inside a macro resolve in the caller's namespace? For example:

(ns a)
(defmacro m [] `(do ::k))

And in another namespace:

(ns b)
(use 'a)
(m)

In this example, (m) resolves to :a/k (the namespace where the macro is defined). I am wondering if there is a way to get it to resolve to :b/k (the namespace where the macro is called).

Upvotes: 6

Views: 441

Answers (1)

amalloy
amalloy

Reputation: 91857

(defmacro m [] (keyword (name (ns-name *ns*)) "k"))

Upvotes: 5

Related Questions