Why some native clojure namespaces should be needed and some not

Simple, as the title says:

Why should I

(require 'clojure.edn) 

to use for example:

 (clojure.edn/read-string "9") 

And why can I immediately call:

 (clojure.string/join (range 4) "-") 
+5
source share
2 answers

Clojure programs start at the top of the "main" namespace (often project-name.core) and rank each form from top to bottom. This happens when the program starts, and before any "basic" functions are activated.

When the require expression is evaluated, it jumps into this namespace and does the same. If a meeting requirement is required, it repeats the branches of these namespaces, recursively loads each namespace as necessary .

So, unless you explicitly state that your namespace requires a different namespace, then you are in the grip of the order that other namespaces require you to load their dependencies. Sometimes this will work, and sometimes unrelated changes in the evaulation order of your distant dependencies will break your code .

So please, please ... declare your own requirements!

+8
source

in repl (just the beginning of clojure ) I have the following ns loaded by default

 user=> (pprint (map #(.getName %) (all-ns))) (clojure.edn clojure.core.server clojure.java.io clojure.java.shell clojure.core.protocols clojure.string clojure.java.browse clojure.pprint clojure.uuid clojure.core clojure.main user clojure.java.javadoc clojure.repl clojure.walk clojure.instant) 

in the space you're in, clojure.edn doesn't seem to load

+1
source

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


All Articles