What is the find-ns method in Clojure?
Overview
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.
The find-ns method
The find-ns method is used to find a namespace in the current code being executed.
Syntax
(find-ns nameof-namespace)
Syntax for the find-ns method
Parameter
This method takes the parameter, nameof-namespace, which represents the name of the namespace.
Return value
This method returns the namespace, if it exists.
Example
(ns clojure.examples.example(:gen-class))(defn func [](println (find-ns 'clojure.string)))(func)
Explanation
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.