Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the fully qualified namespace of a symbol?

If I have a symbol who's namespace is an alias, like q/w, how can I find its actual namespace, say actual.namespace/w ?

I know that resolve will give me the fully qualified var, but I don't know how to get the namespace of a var.

The best I can do is:

 (defn fqns [s] (str (get (ns-aliases *ns*) (symbol (namespace s)))))

surely there's a simpler way ?

like image 598
Hendekagon Avatar asked Dec 27 '22 05:12

Hendekagon


1 Answers

You can get the namespace object of a symbol as shown below (if you want name of ns as string then just call str at the end):

(defn fqns [s] (->> (resolve s) meta :ns))
like image 176
Ankur Avatar answered Jan 09 '23 23:01

Ankur