Clojure Tutorial
Learn Clojure step by step: 36 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- Introduction to Clojure Meet Clojure, a modern Lisp for the JVM and JavaScript built around immutable data, simple functions and a live REPL. Learn what makes it different and where it is used.
- Installing Clojure and Using the REPL Install the Clojure CLI, start a REPL, evaluate forms interactively, and learn about deps.edn, Leiningen, Babashka and editor setups such as Calva, CIDER and Cursive.
- Clojure Syntax and Evaluation Learn how Clojure code is read and evaluated: s-expressions, prefix notation, literals, comments, special forms, quoting and why code is data (homoiconicity).
- Your First Clojure Program Write and run a first Clojure program: project layout, ns declarations, require and refer, defn, println, the -main function, command-line arguments and running with the CLI.
Language Basics
- Numbers and Arithmetic in Clojure Learn Clojure numeric types: 64-bit longs, big integers, exact ratios, doubles and big decimals, plus arithmetic functions, overflow rules, mod versus rem and equality.
- Strings, Characters, Keywords and Symbols Work with text in Clojure: string functions in clojure.string, characters, regular expressions, format, and how keywords and symbols differ and are used as names and map keys.
- Booleans, nil and Conditionals in Clojure Master Clojure truthiness (only nil and false are falsey), the conditional forms if, when, cond, case, condp, if-let and when-let, the logic operators and nil-safe idioms.
- Vars, def and let: Naming Values in Clojure Learn how Clojure names values: global vars with def and defonce, local bindings with let, scope and shadowing, private vars, declare, and why names are not variables you reassign.
- Loops in Clojure: loop, recur, doseq, for and dotimes Learn iteration in Clojure: loop and recur for tail recursion, doseq and dotimes for side effects, the for comprehension, while, and when to prefer map, filter and reduce instead.
Data Structures
- Lists and Vectors in Clojure Understand Clojure's ordered collections: linked lists and indexed vectors, how conj behaves differently, nth, assoc, subvec, peek and pop, and which one to choose for your data.
- Maps in Clojure: assoc, get, merge and Keywords as Functions Learn Clojure maps: literals, get and keyword lookup, assoc, dissoc, update, merge, keys and vals, iterating entries, select-keys, group-by, frequencies and map vs sorted-map.
- Sets in Clojure: Membership, Union and Intersection Use Clojure sets for unique values and fast membership tests: literals, conj and disj, sets as predicate functions, union, intersection, difference, subset checks, sorted-set and uses.
- Immutability and Persistent Data Structures Understand why Clojure data never changes, how persistent vectors, maps and lists share structure so updates stay fast, what transients are, and what identity versus value means.
- Working with Nested Data in Clojure Read and update deeply nested maps and vectors with get-in, assoc-in, update-in and dissoc, reshape data with mapv and into, and model a realistic order with nested structures.
Functions and Higher-Order Functions
- Defining Functions in Clojure: defn, fn and Arities Define Clojure functions with defn and fn, add docstrings and preconditions, use multiple arities, default arguments, variadic parameters with &, the #() shorthand, closures and recursion.
- Destructuring in Clojure: Vectors, Maps and Nesting Pull data apart directly in let, fn and loop bindings: sequential destructuring with & and :as, map destructuring with :keys, :strs, :or, namespaced keys, nesting and keyword arguments.
- Higher-Order Functions: map, filter, reduce, partial, comp Use Clojure's higher-order functions: map, filter, remove, reduce with and without an initial value, apply, partial, comp, juxt, complement, every?, some and sort-by with real examples.
- Composition and Threading Macros in Clojure Write readable data pipelines with the threading macros ->, ->>, as->, some->, some->> and cond->, learn when to use comp or transducers instead, and refactor nested calls into pipelines.
Sequences and Laziness
- The Sequence Abstraction Understand Clojure's sequence abstraction: seq, first, rest, next, cons and conj, and why one set of functions works on lists, vectors, maps, sets and strings.
- Lazy Sequences Learn how Clojure lazy sequences compute values only when needed: range, iterate, repeatedly, cycle, lazy-seq, realization, chunking and common laziness traps.
- Transducers Learn Clojure transducers: composable, reusable transformations that avoid intermediate sequences. Covers map, filter, comp, transduce, into, eduction and early exit.
- Sequence Functions in Practice A practical tour of Clojure's sequence library: map, filter, reduce, for, partition, group-by, frequencies, sort-by, mapcat, into and threading pipelines with real examples.
State and Concurrency
- Identity, State and Atoms Understand Clojure's model of identity and state, then use atoms for synchronous, uncoordinated updates: deref, swap!, reset!, compare-and-set!, watches and validators.
- Refs and Software Transactional Memory Coordinate several pieces of state safely with Clojure refs and software transactional memory: dosync, alter, commute, ref-set, ensure, retries and the bank transfer example.
- Agents, Futures, Promises and Delays Run work asynchronously in Clojure: agents with send and send-off, futures, promises, delays, pmap and deref with timeouts, with guidance on when to use each.
- core.async and Concurrency Patterns Learn core.async channels in Clojure: chan, put!, take!, go blocks, <! and >!, buffers, alts!, timeouts, pipelines and fan-out patterns, with runnable stand-ins.
Macros and Protocols
- Macros: The Basics Learn what Clojure macros are and how to write them: code as data, defmacro, quote, syntax quote, unquote, unquote-splicing and macroexpand with clear examples.
- Writing Better Macros Write safe Clojure macros: avoid variable capture with gensym and auto-gensyms, evaluate arguments once, build binding forms, and know when to prefer functions.
- Protocols and Records Learn polymorphism in Clojure with protocols and records: defprotocol, defrecord, extend-protocol, extend-type, reify, deftype and when to use maps instead.
- Multimethods and Polymorphism Learn Clojure multimethods: defmulti and defmethod, dispatch on any value, :default, derive and isa? hierarchies, prefer-method, and how they compare to protocols.
Tooling and Interop
- Leiningen and deps.edn Set up Clojure projects with Leiningen and the official Clojure CLI: project.clj, deps.edn, aliases, dependencies, running, testing, building an uberjar and choosing a tool.
- Java Interop Use any Java library from Clojure: import, constructors, instance and static methods, fields, doto, type hints, arrays, exceptions, proxy, reify and calling Clojure from Java.
- Testing, spec and REPL-Driven Development Test and validate Clojure code: clojure.test with deftest, is, testing and fixtures, clojure.spec for data validation and generative testing, and the REPL-driven workflow.
Projects and Practice
- Project: Word Frequency Analyzer Build a word frequency analyzer in Clojure: read text, tokenize with regex, count with frequencies and reduce, filter stop words, rank, and run it as a command-line tool.
- Project: Event-Sourced Bank Accounts Build a bank account system in Clojure: immutable data, validation, an event log folded with reduce, atoms and refs for state, transfers in dosync and tests.
- Practice Problems Twelve Clojure practice problems with hints and solutions: sequences, laziness, reduce, maps, recursion, atoms, macros and protocols, plus tips for solving them idiomatically.