Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Use, Require and Import

Tags:

clojure

Can any one give me a good example answer to differentiate between Use, Require and Import.

I hope someone can help me.

like image 895
SamLosAngeles Avatar asked Sep 22 '14 04:09

SamLosAngeles


2 Answers

require ensures that a Clojure namespace has been compiled and instantiated.

  • optionally updating it from source if provided the :reload key
  • optionally creating aliases if the :as key is provided.
  • optionally modifying the current namespace to include mappings to the required namespace's vars, if the :refer key is provided. The mapping is only visible from inside the requiring namespace, and is not transitive to other namespaces requiring it.

use is identical to require in action, except that the default is to modify the current namespace via the refer function to include all the target namespace's vars as if :refer :all had been provided. It accepts the :exclude, :only, and :rename keys to guide the modification of the current namespace.

import is for adding mappings of Class names to the current namespace, so that the package qualifiers will not need to be used.

like image 198
noisesmith Avatar answered Sep 28 '22 03:09

noisesmith


In short, use require

You'll almost never want to mix-up symbols from different namespaces in the same namespace the way use does, except during casual REPL work.

like image 25
Hendekagon Avatar answered Sep 28 '22 05:09

Hendekagon