Clojure from the ground up
A Lisp where the data never changes under you
- Beginner
- 12 chapters
- 205 min read
Learn Clojure by writing it: forms and println, names and values, vectors, maps and sets, decisions with if and cond, functions you define yourself, local names with let, loop and recur, recursion and the stack, map and filter and reduce, the threading arrows, sorting and grouping a pile of rows, ending with a small orders report built from all of it.
What You'll Learn
- Read and write forms, and print with println, print and prn
- Name values with def, and tell numbers, strings and keywords apart
- Read and update vectors, maps and sets with get, assoc and conj
- Choose a branch with if, when and cond, using the two-value truth rule
- Define functions with defn, including more than one way to call them
- Keep a name local with let, and take a map or a vector apart as it goes in
- Repeat work with loop and recur instead of a loop statement
- Write a recursion that ends, and know when the stack is the limit
- Pass functions to map, filter, reduce and apply, including short ones
- Unroll a nest of calls with the threading arrows, first and last
- Sort, count and group rows, and print a report that reads the same every time
- Compose a small report from records held as maps in a vector
Prerequisites
- No programming experience needed — this course starts at the first bracket
- Any other language you know will make the early chapters quick
Course Content
- 01Your first ClojureNot started
What Clojure is, why the operation comes first, and the three ways a program says something out loud.
- 02Names, numbers and textNot started
Naming a value with def, the kind of numbers Clojure keeps without rounding, and the difference between a string and a keyword.
- 03Vectors, maps and setsNot started
The three collections you use every day: a row of values, a table of keys, and a bag that answers yes or no when you ask.
- 04Deciding what to doNot started
if, when and cond, plus the truth rule that makes Clojure decisions easy to read: only nil and false mean no.
- 05Functions you writeNot started
defn, a name that can be called in more than one way, arguments taken apart as they arrive, and the value a function hands back.
- 06Local names with letNot started
let for names that live inside one piece of code, a map or a vector taken apart on the way in, and why naming a value once beats writing it twice.
- 07Loop and recurNot started
How Clojure repeats work without a loop statement: names for the values that change, and recur to start the next pass with new ones.
- 08Recursion, and the stackNot started
A function that calls itself on a smaller problem, the stopping case that ends the walk, and why one shape of recursion runs out of room.
- 09Functions that take functionsNot started
Passing a function to another function: map, filter, reduce and apply, plus the short spelling for a function you only need once.
- 10Passing the value alongNot started
The two arrows that unroll a nest of calls into lines you can read: the value goes in first with one arrow, last with the other.
- 11Sorting, counting and groupingNot started
Turning a pile of rows into a report: sort-by on a key, group-by into buckets, frequencies to count, and doseq to print one line at a time.
- 12A small report, end to endNot started
An orders report built out of everything in the course: maps in a vector, threading with filter, sort-by and map, and one line printed per order.
