Namespaces
Namespaces are a way to organize Clojure functions; you can think of a namespace as being a directory (or file) that stores a particular group of functions. Each directory is independent of other directories; this helps to keep different groups of functions separate and gives a clear structure to your code. It also helps to avoid the confusion that can come with naming clashes.
Consider a situation where you have written a function called calculate-total
, and as part of your project, you're using a library (more on libraries later in this chapter) that also contains a function called calculate-total
. Although these functions have the same name, they work differently, produce slightly different outputs, and are intended to be used in different situations. When you come to use calculate-total
in your code, how does the system know which calculate-function
you actually want? That's where namespaces come in. The two functions will exist in different namespaces,...