Common Lisp Tutorial
Learn Common Lisp step by step: 38 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Common Lisp? Meet Common Lisp: a standardized, compiled, multi-paradigm language famous for macros, the REPL, CLOS and the condition system. Learn what makes it different.
- Installing SBCL and Using the REPL Install Steel Bank Common Lisp on Windows, macOS or Linux, start the REPL, read its prompt and history variables, and learn the commands you need to exit and recover.
- Your First Lisp Programs Write Hello World, print with format, define functions in a file, load and compile code, and build a small temperature converter in Common Lisp step by step.
- REPL Workflow and the Debugger Work the Lisp way: redefine functions live, inspect values, read documentation with describe and apropos, and use the debugger with its restarts to recover from errors.
Syntax and Evaluation
- S-Expressions and Evaluation Understand atoms, lists and S-expressions, the single evaluation rule of Common Lisp, special forms, and how quote and eval stop and start evaluation.
- Numbers and Arithmetic Explore Common Lisp's numeric tower: unbounded integers, exact ratios, single and double floats, complex numbers, rounding functions, and numeric predicates.
- Symbols, Variables and Scope Learn what symbols are, how let, setf, defvar and defparameter create variables, the difference between lexical and dynamic (special) binding, and how packages organize names.
- Characters and Strings Work with characters and strings in Common Lisp: literals, subseq, concatenate, search, comparison, case conversion, and the powerful format directives.
- Conditionals and Equality Make decisions in Common Lisp with if, when, unless, cond, case and typecase, understand NIL and truthiness, and choose between eq, eql, equal and equalp.
- Iteration with loop and do Repeat work in Common Lisp using dotimes, dolist, do and the powerful loop macro with for, collect, sum, when, while, and early exit with return.
Lists and Data Structures
- Conses and Lists Understand how Lisp lists are built from cons cells, how car, cdr and cons work, what dotted pairs are, and how shared structure and destructive changes behave.
- List Functions Process lists the Lisp way with mapcar, remove-if, find-if, reduce, every, some, sort, remove-duplicates and the set operations union and intersection.
- Association Lists and Property Lists Store key-value data in plain Lisp lists with association lists and property lists: assoc, acons, getf, setf getf, remf, and when to switch to hash tables.
- Vectors, Arrays and Sequences Use Common Lisp vectors and multi-dimensional arrays, adjustable vectors with fill pointers, and the generic sequence functions with :key, :test, :start and :end.
- Hash Tables Store and look up data by key in Common Lisp with hash tables: make-hash-table, gethash and its second value, remhash, maphash, loop over keys, and choosing eql or equal.
Functions and Closures
- Functions and Parameters Define Common Lisp functions with defun and its lambda list: required, &optional, &rest and &key parameters, defaults, supplied-p flags, and multiple return values.
- Lambda and Higher-Order Functions Treat functions as values in Common Lisp: lambda expressions, #' and the function special form, funcall and apply, Lisp-2 namespaces, flet, labels and function composition.
- Closures and Lexical Scope Learn how Common Lisp closures capture lexical variables to keep private state: counters, accumulators, shared state between functions, memoization and loop-variable pitfalls.
- Recursion and Tail Calls Think recursively in Common Lisp: base cases, recursing on lists and trees, accumulators, tail calls and what SBCL does with them, mutual recursion with labels, and memoization.
Macros
- Macros: Code as Data in Common Lisp Learn what Common Lisp macros are, why homoiconicity makes them possible, how a macro differs from a function and when evaluation order forces you to write one.
- defmacro and Backquote Templates Write Common Lisp macros with defmacro, backquote, comma and comma-at, use &body and &key lambda lists, and see how templates replace manual list building.
- macroexpand and Debugging Macros Learn macroexpand-1, macroexpand, pretty-printing and the habits that make Common Lisp macros debuggable: test expansions first, read errors and avoid compile-time surprises.
- Variable Capture, gensym and Multiple Evaluation Understand the two classic macro bugs in Common Lisp, variable capture and multiple evaluation, and fix them with gensym, once-only style bindings and careful package use.
- Macro Patterns: with- Macros, Loops and Control Flow Learn the macro patterns used in real Common Lisp code: with- cleanup macros, while and do- loops, anaphoric macros, defining DSL forms and when to prefer functions.
- Reader Macros, Compiler Macros and macrolet Go beyond defmacro in Common Lisp: reader macros and the readtable, macrolet and symbol-macrolet for local syntax, compiler macros for optimization and eval-when staging.
CLOS Object System
- CLOS: Classes, Slots and Instances Meet the Common Lisp Object System: define classes with defclass, configure slots with initargs, readers, writers and defaults, create instances and inspect them.
- CLOS: Generic Functions, Methods and Multiple Dispatch Learn CLOS generic functions and defmethod in Common Lisp: dispatch on argument classes, eql specializers, multiple dispatch and how methods are chosen.
- CLOS Inheritance and Method Combination Understand CLOS inheritance and the class precedence list, call-next-method, :before, :after and :around auxiliary methods, multiple inheritance and mixins in Common Lisp.
- CLOS Initialization, Slots and the Metaobject Protocol Customize object creation with initialize-instance and :after methods, validate slots, define print-object, use change-class and see how the CLOS metaobject protocol works.
Condition System
- Conditions: Signaling and Handling Errors Learn the Common Lisp condition system: define-condition, error, warn and signal, handler-case versus handler-bind, condition hierarchies and why handlers run before the stack unwinds.
- Restarts: Recovering Without Unwinding Master Common Lisp restarts: restart-case, invoke-restart, with-simple-restart, use-value and continue, and how low-level code offers recovery choices while policy lives higher up.
- Non-Local Exits, Assertions and Cleanup Learn Common Lisp non-local exits with block and return-from, catch and throw, guarantee cleanup with unwind-protect and check inputs with assert, check-type, ecase and etypecase.
Libraries and Tooling
- Packages and ASDF Systems Organize Common Lisp code with defpackage, in-package, export and import, then describe projects with ASDF .asd files, dependencies, load order and test systems.
- Quicklisp and the Common Lisp Library Ecosystem Install Quicklisp, load libraries with ql:quickload, explore dists, Ultralisp and Roswell, and tour essential Common Lisp libraries for utilities, strings, regex, JSON, HTTP and threads.
- Testing, Debugging and Delivering Common Lisp Programs Test Common Lisp code with FiveAM, debug with trace, step, inspect and the interactive debugger, profile with sb-sprof and deliver a standalone executable with save-lisp-and-die.
Projects and Practice
- Project: Build a Mini Test Framework with Macros Build a small unit-test framework in Common Lisp step by step, using defmacro, gensym, special variables and conditions, then run a stand-in version in JavaScript.
- Project: Bank Accounts with CLOS, Conditions and Restarts Build a bank account system in Common Lisp that combines CLOS classes, generic functions, method combination, custom conditions and restarts, with a runnable JavaScript model.
- Practice: Common Lisp Macro, CLOS and Condition Exercises Practice Common Lisp with graded exercises on macros, CLOS, conditions and tooling, with worked solutions, idioms, common pitfalls and a style checklist.