开发者

What are the differences among `require`, `import`, and `use`? [duplicate]

This question already has answers here: difference between use and require (4 answers) Closed 9开发者_如何学Python years ago.

Why do we need all of require, import, and use?


Require

require loads a Clojure library so that you can use it in your current file or REPL.

This is the normal way to access functions and definition in a Clojure library.

Use

use brings in a Clojure namespace in the same way as require, but in addition it refers to the definitions in the loaded namespace from the current namespace (i.e. it creates a convenient alias in the current namespace).

Don't over-use it (pun intended) - it can easily cause namespace conflicts!

Import

import is for importing Java classes and interfaces only.

user=> (import java.util.Date)
java.util.Date

user=> (def *now* (Date.))
#'user/*now*

If you don't need to interoperate with Java code then you can safely ignore import.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜