Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 38 ยท 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.

Common Lisp is a general-purpose programming language with a long memory and a modern toolbox. It descends from Lisp, which John McCarthy described in 1958, making it one of the oldest families of languages still in active use. Common Lisp itself was designed in the 1980s to unify several competing Lisp dialects and was published as an ANSI standard in 1994. The standard has not changed since, which is why a program written decades ago usually still runs today.

People keep choosing Common Lisp for a handful of reasons: it can be compiled to fast native code, it lets you change a running program without restarting it, its macro system lets you extend the language itself, and it ships with a rich object system (CLOS) and a unique error-handling design (the condition system). This lesson gives you the map before we walk the roads.

Honest note about this course. The Common Lisp compiler cannot run inside a web page, so the Lisp blocks in this course are read-only. Where a runnable demo helps, we give you a clearly labelled stand-in written in JavaScript. Some lessons use a tiny Lisp interpreter written for this site, the "Mini-Lisp". It understands a small slice of the language so you can experiment with parentheses and evaluation. It is not SBCL, so details (like printing, namespaces and error messages) differ from the real thing. Every real Common Lisp transcript shown is marked as such.

A first look

Here is real Common Lisp. Do not worry about understanding every character yet.

LISP
(defun greet (name)
  "Return a greeting for NAME."
  (format nil "Hello, ~a!" name))

(greet "Ada")   ; => "Hello, Ada!"

Everything is written as a list in parentheses: the first element is the operator (here defun, then greet, then format), and the rest are its arguments. There is no separate statement syntax, no semicolons ending lines, and no operator precedence rules to memorize. The same list notation is used for code and for data, and that single fact explains most of what makes Lisp special.

What sets Common Lisp apart

Why people love Common Lisp

Live REPL Change a running program.
Macros Write code that writes code.
Compiled Native speed with dynamic power.
Stable standard ANSI 1994, still current.

Four ideas you will meet again and again.

1 / 2

The REPL and the image

You normally work in a REPL (read-eval-print loop). It reads a form, evaluates it, prints the result, and loops. Unlike a script that you run from the top, a Lisp session stays alive. You define a function, test it, redefine it, and test again, all without losing your data. Many Lisp programmers keep one session running for days.

Code is data

A Lisp program is made of lists, and lists are also the main data structure. A macro is a function that receives code as a list, rearranges it, and returns new code before the compiler sees it. With macros, features that other languages need a new compiler release for (loops, pattern matching, query languages) can be written as ordinary libraries.

Compiled and dynamic at once

Common Lisp implementations such as SBCL compile every function to machine code, yet the language is dynamically typed and fully interactive. You can add optional type declarations to make hot paths run close to the speed of C, without giving up the interactive workflow elsewhere.

A Lisp-2

Common Lisp keeps functions and variables in separate namespaces (it is a "Lisp-2"). You can have a variable named list and still call the function list. We return to this in Symbols, Variables and Scope and Lambda and Higher-Order Functions.

Implementations

Common Lisp is a specification, not a single program, so there are several implementations that all run the same standard code.

Implementation Notes
SBCL Free, very fast native compiler, the most popular choice
CCL (Clozure) Free, fast compile times, good threads
ECL Embeddable, compiles through C
ABCL Runs on the Java Virtual Machine
CLISP Bytecode-compiled, small and portable
Allegro CL, LispWorks Commercial, with large IDEs and support

Throughout this course the examples follow the standard and are written with SBCL in mind. When something is implementation-specific, we say so.

Common Lisp compared with its relatives

Lisp is a family. Clojure and Scheme are cousins, not the same language.

  • Scheme is small and minimal; Common Lisp is large and "batteries included" for systems programming.
  • Clojure runs on the JVM, favors immutable data and has square brackets; Common Lisp has mutable data, native compilation and CLOS.
  • Emacs Lisp is the editor's extension language and is much closer to Common Lisp than to Scheme, but it is not the same.

Try it: evaluating the first form

This stand-in reads text, evaluates it, and prints the result, which is exactly the shape of a real REPL. It runs on the site's Mini-Lisp, not on SBCL.

JS Mini-Lisp: a tiny REPL

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Each form prints as * form followed by its value, so you can see how read, eval and print fit together. Note that Mini-Lisp prints quote forms in full ((QUOTE X)); real Common Lisp prints 'X.

A taste of macros and conditions

Do not worry about these yet: they get their own chapters. They show the flavor.

LISP
;; A macro: a new control structure in 3 lines
(defmacro unless-zero (n &body body)
  `(if (zerop ,n) nil (progn ,@body)))

;; The condition system: handle an error AND choose how to continue
(handler-case (/ 10 0)
  (division-by-zero () :oops))   ; => :OOPS

Where Common Lisp is used

Lisp has powered computer algebra systems, airline fare search, CAD, theorem provers, and music and game tools. Modern Common Lisp is used for backend services, data tools, compilers, and teaching. The key advantage is long-term stability plus a language you can reshape to fit your problem.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does REPL stand for?

    A REPL reads a form, evaluates it, prints the result and repeats.
  2. 2. Why is Common Lisp called a Lisp-2?

    A symbol can name a function and a variable at the same time, so (list list) is legal.
  3. 3. Common Lisp is defined by...

    ANSI X3.226-1994 defines the language; SBCL, CCL, ECL and others implement it.
  4. 4. What does it mean that code is data in Lisp?

    Because code is made of lists, a macro can receive code as a list and return new code.

Summary

  • Common Lisp is an ANSI-standardized, compiled, interactive, multi-paradigm language from the Lisp family.
  • You work in a REPL and can change a running program.
  • Code is written as lists, which makes macros possible.
  • CLOS (objects) and the condition system (errors) are built in.
  • Several implementations exist; SBCL is the most common.
  • On this site, Lisp blocks are read-only and the runnable demos are labelled JavaScript stand-ins.

Next: Installing SBCL and Using the REPL