Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

namespace
clojure
communitycreator

What is the *ns* method in Clojure?

Chinweuba Elijah Azubuike

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

Overview

Namespaces in Clojure are used to distinguish classes into separate logical parts. We use them when we have multiple imported classes in our code. The *ns* method is one of the methods used to work with namespaces.

What is the *ns* method?

The *ns* method is used to get the current namespace of our code.

Syntax

(*ns*)
Syntax for the *ns* method

Parameter

The *ns* method does not have a parameter. That is, no parameter is passed to it.

Return value

The *ns* method returns the current namespace of your code, i.e., wherever the *ns* method is used, it returns the namespace of the code. Let's look at an example.

Example

(ns clojure.examples
(:gen-class))
(defn func []
(println *ns*))
(func)
Example of the *ns* method

Explanation

  • Line 3: We define a function func .
  • Line 4: We use the *ns* method and print out the output. Note that the output is an object that contains the namespace of our code.
  • Line 5: We call the function func .

RELATED TAGS

namespace
clojure
communitycreator

CONTRIBUTOR

Chinweuba Elijah Azubuike

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring