In the Wild

Since garden-variety vars are the mortar that binds Clojure code together, they are everywhere in real-world code. In fact, def figures into some of the first code that runs when Clojure boots up.[15] Here are slightly simplified versions of a couple of defs that get run very early on:

 (​def​ second (​fn​ second [x] (first (next x))))
 
 (​def​ ffirst (​fn​ ffirst [x] (first (first x))))

These are just two handy functions: second, which pulls the second item off of a collection, and ffirst, which takes the first item from a collection—which itself should be a collection—and pulls the first item off of it. You might wonder why this code goes to the trouble of using def and fn instead of the sleeker defn. The answer is simple: these ...

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.