Clojure Namespaces - “require”
Loads a namespace if not already loaded. It takes an argument(symbol) which should be a quoted
(require 'clojure.string)
;; => nil
After requiring a namespace, we need to refer the functions in a fully qualified names. Like,
(require 'clojure.string)
;; => nil
(clojure.string/split "This is an example of require" #" " )
;; => ["This" "is" "an" "example" "of" "require"]
Other way is to alias a namespace at the time of requring using as
.
(require '[clojure.string :as string])
;; => nil
(string/capitalize "hello")
;; => "Hello"
The vector here is to avoid quoting every symbol, clojure.string
and string
.