Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 928
Aaron Iba Avatar asked Apr 01 '13 00:04

Aaron Iba


1 Answers

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

like image 108
amalloy Avatar answered Oct 10 '22 06:10

amalloy