Chapter 3. Building blocks of Clojure

 

This chapter covers

  • Clojure metadata
  • Java exceptions
  • Higher-order functions
  • Scoping rules
  • Clojure namespaces
  • Clojure’s destructuring feature
  • Clojure’s reader literals

When people are good at something already (such as a programming language), and they try to learn something new (such as another programming language), they often fall into what Martin Fowler (martinfowler.com/bliki/Improvement-Ravine.html) calls an “improvement ravine.” For programming, the ravine refers to the drop in productivity experienced when one has to relearn how to do things in the new language. We’ve all been guilty of switching back to a language we’re already good at to get the job done. It sometimes takes several attempts to get over enough of the ravine to accomplish simple things. The next few chapters aim to do that—we’ll review the basics of Clojure in more detail. After reading them, you’ll be comfortable enough to solve problems of reasonable complexity. We’ll also cover most of the remaining constructs of the language, many of which will be familiar to you if you use other common languages.

First, we’ll examine metadata, which is a unique way to associate additional data with an ordinary Clojure value without changing the value. Next, we’ll show you another piece of Java interop: exception handling and throwing.

3.1. Metadata

3.2. Java exceptions: try and throw

3.3. Functions

3.4. Scope

3.5. Namespaces

3.6. Destructuring

3.7. Reader literals

3.8. Summary