A Global, Stable Place for Your Stuff

As we discovered all the way back in Chapter 1, def is about as simple as programming-language features come. You just hand it a symbol and a value:

 (​def​ title ​"Emma"​)

And it binds the symbol to the value. We’ve also seen that in contrast to the very local and temporary let, you use def for longer-lasting, more stable name-to-value bindings. Let’s start with the stable part: the rule is that a binding created with def will hang around until either you change it or the program terminates. This makes def perfect for constants:

 ;; Everyone's favorite universal constant.
 
 (​def​ PI 3.14)
 
 ;; Length of a standard book ID.
 
 (​def​ ISBN-LENGTH 13)
 
 ;; Company names are more or ...

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.