获取可用的Clojure名称空间 [英] Get available clojure namespaces

查看:62
本文介绍了获取可用的Clojure名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种惯用的方法来获取可用的可用命名空间?

Is there an idiomatic way to get available namespaces that can be used?

(all-ns)仅返回已经使用的名称空间. (Package/getPackages)返回所有可用于import的Java程序包,但仅返回那些已经使用的Clojure名称空间.

(all-ns) returns only already used namespaces. (Package/getPackages) returns all Java packages available for import, but only those Clojure namespaces that are already used.

然后我偶然发现了这篇文章,但是它使用了一些类路径魔术.

Then I stumbled upon this post, but it uses some classpath magic.

如果我的类路径上有clojure.jar和contrib.jar,但我还没有用过,我想得到类似('clojure.core 'clojure.set ... 'clojure.contrib.accumulators 'clojure.contrib.condition ...)的东西.

So I want to get something like ('clojure.core 'clojure.set ... 'clojure.contrib.accumulators 'clojure.contrib.condition ...) if I have the clojure.jar and contrib.jar on my classpath, but I haven't used anything yet.

推荐答案

您将需要执行类路径魔术".由于没有任何注册表,因此您必须遍历类路径并查看每个clojure源文件以确定可用的命名空间. (以防未对文件进行AOT编译.否则,您将需要其他启发式方法.)

You will need to do "classpath magic". Since there is no kind of registry, you have to walk the classpath and look in every clojure source file to determine what namespaces are available. (In case the files are not AOT compiled. Otherwise you'll need a different heuristic.)

我认为链接文章中使用的功能是最好的选择:clojure.contrib.find-namespaces/find-namespaces-on-classpath.

I think the function used in the linked post is the best way to go: clojure.contrib.find-namespaces/find-namespaces-on-classpath.

从Clojure 1.3.0开始不推荐使用;现在使用 http:中的clojure.tools.namespace.find/find-namespaces和clojure.java.classpath/classpath. //github.com/clojure/java.classpath

Deprecated since Clojure 1.3.0; use now clojure.tools.namespace.find/find-namespaces and clojure.java.classpath/classpath from http://github.com/clojure/java.classpath

这篇关于获取可用的Clojure名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆