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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With