What's the difference between use
and :use
in the ns
macro?
Docs says the following:
Use :use in the ns macro in preference to calling this directly
It is a bit confusing.
In the ns
form, you want to use the keyword version (:require ...)
like:
(ns clj.core
(:require [tupelo.core :as t] ))
You should consider this the "normal" way of doing things.
The other version, without the colon, is a function of the same name that can be called at the REPL in case you can't or don't want to use the ns
form. This would look like:
> lein repl
user=> (require '[tupelo.core :as t] )
nil
user=> (t/append [1 2 3] 4)
[1 2 3 4]
Please note: For the repl/function version, you must also quote the vector containing the namespace specs. Notice that we did not quote the spec in the ns
version using :require
.
As an alternative, if you are already in the editor and just want to test something quick at the REPL, you can cut/paste the whole ns
form from the top of your file into the REPL:
> lein repl
user=> (ns clj.core
#_=> (:require [tupelo.core :as t] ))
user=>
which is easier and less error-prone than typing the function-version by hand.
For a good overview please see the recent blog posting here: https://stuartsierra.com/2016/clojure-how-to-ns.html