May 2018
Beginner to intermediate
290 pages
6h 43m
English
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 ...
Read now
Unlock full access