Namespaces in Clojure are used to distinguish classes into separate logical parts. It is used when we have multiple imported classes in our code. The find-ns
method is one of the methods used to work with namespaces.
find-ns
methodThe find-ns
method is used to find a namespace in the current code being executed.
(find-ns nameof-namespace)
This method takes the parameter, nameof-namespace
, which represents the name of the namespace.
This method returns the namespace, if it exists.
(ns clojure.examples.example(:gen-class))(defn func [](println (find-ns 'clojure.string)))(func)
Line 3: We define a function, func
.
Line 4: We use the find-ns
method and print the output. Notice that the output is an object containing the name of the namespace we passed to the find-ns
method.
Line 5: We call the function, func
.