用于检查当前“使用”哪些命名空间的函数/宏以及如何检查是否使用了某个特定的?
Clojure 中是否有函数/宏来检查当前“已使用”哪些命名空间?哪一个?所以我的意思并不是“我们当前位于哪个命名空间”,而是例如,我想找出“clojure.contrib.string”当前是否“使用”,如 (use 'clojure.contrib.string)
。我的意思不是“必需”。
如何编写一个函数,在使用“clojure.contrib.string”(通过符号提供的命名空间的名称)时给出 true,否则给出 false? (defn ns-used? [名称] (...)
Is there a function/macro in Clojure to check what namespaces are currently 'used'? Which one? So I don't mean 'what namespace are we currently in' but for example, I want to find out if 'clojure.contrib.string' is currently 'used' as in (use 'clojure.contrib.string)
. I don't mean 'required'.
How does one write a function that give true when for example 'clojure.contrib.string (the name of the namespace provided via a symbol) is used and false otherwise?
(defn ns-used? [name] (...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
all-ns 按照kotarak的建议,与您正在寻找的内容很接近,但它还为您提供了所有
所需
但尚未引用的名称空间。否则 ns-refers 会给你一个命名空间中引用的所有函数的映射。类似且可能也令人感兴趣的是 ns-map< /a> 和 ns-imports这给了你所有导入的类或记录的映射。
如果您想严格查找引用函数的所有命名空间,您可以执行以下操作:
如果您很乐意检查命名空间是否已被
required
或used
你可以这样做你必须传递引用中的符号:
all-ns as suggested by kotarak, is close to what you are looking for, but it also gives you all the namespaces that have been
required
without having been referred.Otherwise ns-refers gives you a map of all the functions that are referred in the namespace. Similar and possibly also of interest are ns-map and ns-imports which gives you a mapping of all the imported classes or records.
If you want to strictly find all the namespaces from which functions have been referred, you could do something like this:
If you are happy to check if the namespace has been
required
orused
you could doYou will have to pass the symbol in quoted:
all-ns 一些合适的定义的“二手”。
ns-refers 一些其他定义的“二手”。
all-ns for some suitable definition of 'used'.
ns-refers for some other definition of 'used'.