The difference between use, demand and import

Can someone give me a good example of an answer to distinguish between usage, requirement and import.

Hope someone can help me.

+5
source share
3 answers

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

  • optionally updating it from the source if the key is provided :reload
  • aliases are optional if the :as key is provided.
  • it is not necessary to modify the current namespace to include mappings in the required namespace if the :refer key is specified. The mapping is visible only within the required namespace and is not transitive for other namespaces requiring it.

use is identical to the requirement in action, except that by default, changing the current namespace using the refer function is used to include all target namespaces, as if :refer :all . It accepts the keys :exclude :only and :rename to indicate modifications to the current namespace.

import designed to add class name mappings to the current namespace, so you won’t need to use package qualifiers.

+7
source

In short, use require

You almost never want to mix characters from different namespaces in the same namespace, as use does, unless REPL happens to work randomly.

+1
source

require downloads and compiles Clojure namespaces. import avoided by using fully qualified Java class names (the same as import in Java).

0
source

Source: https://habr.com/ru/post/1203108/


All Articles