如何找到符号的完全限定名称空间? [英] How to find the fully qualified namespace of a symbol?
本文介绍了如何找到符号的完全限定名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个符号,其名称空间是别名(例如q/w),那么如何找到其实际名称空间,例如actual.namespace/w?
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 ?
我知道resolve
将给我完全限定的var,但我不知道如何获取var的命名空间.
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 ?
推荐答案
您可以获取符号的名称空间对象,如下所示(如果要将ns的名称作为字符串,则只需在末尾调用str):
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))
这篇关于如何找到符号的完全限定名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文