Why do we need all of require
, import
, and use
?
Asked
Active
Viewed 7,201 times
1 Answers
68
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.

Vincent Cantin
- 16,192
- 2
- 35
- 57

mikera
- 105,238
- 25
- 256
- 415
-
10This question was incorrectly marked as a duplicate. The referred-to answer does not explain "import". This should be the accepted answer. – battey May 10 '16 at 23:13