As and Refer

The downside of using fully qualified names like blottsbooks.pricing/discount-price is that they can get long, and long names tend to clutter up your code and make it less readable. Fortunately, Clojure provides a couple of shortcuts to minimize the clutter.

One way you can make your code less noisy is to create an alias for the namespace, like this:

 (require '[blottsbooks.pricing :as pricing])

or like this:

 (ns blottsbooks.core
  (:require [blottsbooks.pricing :as pricing])
  (:gen-class))

Note that we’re now feeding require a three-element vector instead of just the name of the namespace. As shown in the figure, the extended version of require not only pulls in the blottsbooks.pricing namespace but also gives it an alias of ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.