clarify different link functions in clojure
A great useful tutorial and I am there to make this summary.
refer
refer takes a symbol argument and maps all the public symbols from that namespace into the current namespace.
The symbols are still mapped to the values in their original namespace. By calling refer in the example, you created a namespace mapping from the symbol greetings/println
to the Var #'clojure.core/println
.
1 |
|
require
To link another class/function with our namespace, but its own namespace kept. Needs canonical namespace to invoke.
Loads libs, skipping any that are already loaded. Each argument is either a libspec that identifies a lib, a prefix list that identifies multiple libs whose names share a common prefix, or a flag that modifies how all the identified libs are loaded. Use :require in the ns macro in preference to calling this directly.
1 |
|
As you need to use namespace/function
to refer to target function.
use
To import another class/function into our namespace, hence target namespace just like merged
into your namespace.
This function combined require
and refer
. But for recent version, they tend to deprecated use
by using (require '[clojure.data.json :refer :all])
.
1 |
|
You just need to use function
to refer to target function directly without referring namespace.
import
To import Java
class into namespace and shorten the invock name.
1 |
|
You could shorten the canonical name and just need to use simple name of a class
to refer to target class
namespace declare
To simply those kinds of link function, use (ns)
function to bring them all together.
1 |
|
You could use random quantity of any :use
:require
and :import
in this function.
example
An original innovated prime number function:
1 |
|