Does Clojure have an equivalent of Java's import package.*?

百般思念 提交于 2019-11-30 21:51:16

问题


Or do I have to specifically enumerate every class that I import?

I'm just learning Clojure now, and it seems useful to be able to do something like this in the REPL:

(import '(java.io *))

Not that this is valid syntax, but it would be nice to have something that does the equivalent. It would save some typing, especially when tinkering around. In actual production code I always enumerate each class that I'm importing, regardless of the language, but it's pretty convenient not to have to do so.


回答1:


Rich Hickey explains why it is not possible.




回答2:


Unless I missed an update, there is no way to wild card include packages into a namespace in Clojure currently.




回答3:


There seems to be no ways of doing that currently. The import macro is only there to import the specified classes into the current namespace. I've tried to write another macro to do what you want, but it doesn't appear to be possible with the class loader used by Clojure as it doesn't let us access package resources.



来源:https://stackoverflow.com/questions/1990714/does-clojure-have-an-equivalent-of-javas-import-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!