Clojure Koans
Clojure is a modern Lisp: a small, consistent language built around immutable data and functions that transform it. Programs are made of plain maps, vectors and sets rather than classes, and macros let the language grow with your needs. It runs on the Java platform and, as ClojureScript, in JavaScript, which is how it runs here. These koans cover its data structures, sequences and laziness, functions and destructuring, state with atoms, protocols, records and multimethods, and macros.
79 koans in 18 groups, tested with clojure.test. Each is a small program whose tests fail: replace every ___ until they pass.
Awakening
How a koan checks your answers, and what Clojure counts as true.
Numbers
Arithmetic, comparisons, and the functions that work on numbers.
Strings
Building strings, taking them apart, and searching them with regular expressions.
Lists and vectors
Ordered collections: vectors to index into, lists to build from the front.
Maps
Keys to values: looking up, adding, changing, and reaching into nested maps.
Sets
Collections of unique values, and the operations between them.
Sequences
One abstraction for every collection: first, rest, and the functions built on them.
Map, filter and reduce
Transforming collections with functions: the heart of Clojure.
Functions
Defining functions, and building new ones from old.
- Defining functions
- Arities and variadic functions
- Anonymous functions
- Building functions
- Closures
- Functions as values
- Memoize
Destructuring
Taking collections apart right where you name things.
Control flow
Choosing what to do: if, when, cond, case, and naming values with let.
Threading macros
Writing a pipeline of steps from top to bottom.
Recursion and laziness
Looping without changing anything, and sequences computed only when needed.
State
Changing things safely: atoms, watches, and values computed on demand.
Records, protocols and multimethods
Polymorphism in Clojure: protocols dispatch on types, multimethods on anything.
Macros
Code is data: quoting it, building it, and writing macros that write code.
Errors
Throwing and catching, with errors that carry data.
Puzzles
Small programs to read and predict.