All about Namespaces

What are namespaces?

In Clojure, a namespace is a way to organize code and avoid naming conflicts between functions, variables, and other definitions. A namespace is a named container for a set of related definitions, such as functions, macros, and data structures. We can compare them to the idea of packages or modules in object-oriented programming languages.

We’ve mentioned them a few times since the beginning of this course, mostly to describe the namespaces with default values that Clojure has available for use in its common, core libraries. Nevertheless, they’re not only used for that but also to help us define our code in an idiomatic way and relate it to different files to create a service.

Declaring namespaces

To create a namespace in Clojure, we use the ns special form followed by the namespace name, which can be a composition of words to define its location in the folder's structure or only the name that this file represents. This is how we define a namespace:

Get hands-on with 1200+ tech skills courses.