Lumenary CS · Programming languages
Clojure
A modern Lisp on the Java platform built around immutable data, plain maps and a live REPL, from a first program to professional practice.
Clojure is a dynamic, functional dialect of Lisp that Rich Hickey released in 2007. It runs on the Java Virtual Machine and can call any Java library, and its sister language ClojureScript compiles to JavaScript. Its defining ideas are immutable, persistent data structures; programs built from small functions over plain maps and vectors; a small set of carefully designed tools for managing state that changes over time; and a workflow in which you grow a program inside a running REPL instead of restarting it after every edit. It is used for web services and back-end systems, data processing, financial software (a large Brazilian bank, Nubank, runs much of its business on it) and anywhere a team values simple, data-oriented code.
This course is for anyone who already knows what a variable, a loop and a function are: the Start level of Lumenary CS or equivalent experience in any language. No Lisp or Java experience is assumed. It starts with the parentheses and the REPL, works through immutable data, functions, sequences and data-oriented design, and ends with state and concurrency, Java interop, macros, testing, the tools professionals use every day and a complete small project.
To run the code, install a Java runtime and the Clojure CLI by following the official guide at clojure.org/guides/install_clojure; save a program as main.clj and run it with clojure -M main.clj, or start a REPL with clj. Clojure has no official online playground. Every complete program in these lessons was run with Clojure 1.12 on Java 21 by Lumenary's test suite, using only the core library, and the output shown is the output it printed. The lessons were drafted with AI assistance and are awaiting review by a human computer scientist.
- Chloe · The Designer
“Why is the language built this way?” - Margaret · The Profiler
“What does it print, and what does it cost?” - Gideon · The Language Lawyer
“What exactly does the language guarantee?”
Foundations · 3 lessons
Foundations
Install the Clojure CLI, read and write Lisp syntax at the REPL, and learn the core of the language: immutable collections, functions, control flow and destructuring.
- 1First steps: Lisp syntax, the REPL and the Clojure CLIWhere Clojure came from, how to install and run it, and how to read the parentheses. 50 min
- 2Immutable, persistent dataVectors, maps, sets and lists that never change, and why that makes programs simpler. 55 min
- 3Functions, control flow and destructuringDefining functions, choosing between branches, looping with recur, and pulling data apart by its shape. 60 min
Practice · 3 lessons
Practice
Transform data with lazy sequences and transducers, model a domain with plain maps, namespaces, protocols and spec, and manage changing state with atoms, refs and agents.
- 4Sequences, laziness and transformationOne abstraction for every collection, infinite sequences computed on demand, threading pipelines and transducers. 60 min
- 5Maps as data: namespaces, polymorphism and specModel a domain with plain data, organise code in namespaces, dispatch with multimethods and protocols, and describe data with spec. 65 min
- 6State and concurrency: atoms, refs and agentsValues never change, but the world does. How Clojure models changing state safely, even across many threads. 65 min
Professional · 2 lessons
Professional
Use the Java platform from Clojure, handle errors and write macros with care, test with clojure.test, know the tools and the ClojureScript side of the ecosystem, and build a complete project.
- 7The host and the language: Java interop, errors and macrosReach down into the Java platform, handle failure with exceptions that carry data, and extend Clojure's syntax with macros. 65 min
- 8Testing, tooling and a complete projectclojure.test, the Clojure CLI and Leiningen in depth, the tools professionals use, ClojureScript, and a small program built the idiomatic way. 70 min
Further reading and resources
- ClojureThe official home of the language: guides, the language reference, news and community links.
- Install ClojureThe official installation guide for the Clojure CLI on macOS, Linux and Windows.
- Clojure language referenceThe reference pages, starting with the reader (Clojure's syntax); the sidebar lists the rest.
- Clojure API documentationEvery function in clojure.core and the other namespaces that ship with Clojure.
- Clojure cheatsheetThe core library grouped by task, one line per function. Keep it open while you learn.
- Rationale · Rich HickeyWhy Clojure was created, in its author's words.
- ClojureScriptClojure compiled to JavaScript, for browsers and Node.js.