Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 38 ยท Getting Started

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.

To run Common Lisp on your own computer you need an implementation. The easiest and most common choice is SBCL (Steel Bank Common Lisp). It is free, fast, actively maintained and available on every major operating system. This lesson shows how to install it, how to start the REPL, what its prompt tells you, and the small set of commands that make the REPL comfortable.

You cannot run SBCL in the browser, so install blocks and REPL sessions in this lesson are read-only. The runnable demo at the end is a labelled JavaScript stand-in for the REPL history variables.

Installing SBCL

Pick the line for your system. Commands change over time, so check the SBCL website if one fails.

Terminal
# Debian / Ubuntu
sudo apt install sbcl

# macOS with Homebrew
brew install sbcl

# Windows with Scoop or Chocolatey
scoop install sbcl
choco install sbcl

# Fedora
sudo dnf install sbcl

On Windows you can also download the installer from the SBCL project page. Afterwards, open a new terminal and check the version:

Terminal
sbcl --version

It prints something like SBCL 2.x.y. Any recent 2.x release is fine for this course.

Starting the REPL

Type sbcl in a terminal. A banner appears, then the prompt *:

TEXT
This is SBCL 2.x.y, an implementation of ANSI Common Lisp.
...
* 

Type a form and press Enter. The REPL evaluates it and prints the value:

LISP
* (+ 2 3)
5
* "hello"
"hello"
* (list 1 2 3)
(1 2 3)

The prompt * means "ready for a form". When an error happens, you drop into the debugger and the prompt changes to 0] (the number is the debugger level). We cover that in REPL Workflow and the Debugger.

Exiting

Any of these works:

LISP
* (exit)               ; standard-ish way in SBCL
* (sb-ext:exit)        ; the SBCL package-qualified name
* (quit)               ; older alias, still works

You can also press Ctrl-D at an empty prompt (end of input). Ctrl-C interrupts a running computation and enters the debugger.

The REPL's special variables

The REPL remembers your last results so you can reuse them.

Variable Meaning
* The value of the most recent form
** The value before that
*** The value before that
+ The most recent form itself
++ , +++ Earlier forms
/ List of the multiple values of the last form
LISP
* (+ 10 5)
15
* (* * 2)           ; first * is the function, second * is the last value 15
30
* (list * **)       ; 30 and the one before it, 15
(30 15)

Notice that * is both a function (multiplication) and a variable (last value). This is the Lisp-2 idea from What Is Common Lisp?: the first position of a list is looked up as a function, the other positions as variables.

Here is a stand-in that models the three history variables. It is plain JavaScript, not SBCL.

JS Stand-in: REPL history variables

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

No output.

Loading code and running scripts

You will soon keep your code in files, usually with the extension .lisp.

LISP
* (load "hello.lisp")     ; read and evaluate every form in the file

From the shell, three useful flags:

Terminal
sbcl --load hello.lisp                 # load a file, then stay in the REPL
sbcl --script hello.lisp               # run it and exit, no banner, no REPL
sbcl --noinform --eval '(print (+ 1 2))' --eval '(exit)'

--script is ideal for small command-line programs. It also sets sensible defaults: errors print a backtrace and exit instead of opening the interactive debugger.

Quality of life: rlwrap

Plain SBCL has no line editing: the arrow keys print strange characters. The free tool rlwrap fixes that on macOS and Linux:

Terminal
rlwrap sbcl

Better still, use an editor integration (SLIME or SLY for Emacs, Alive for VS Code, or Vim with Slimv) where the REPL is a buffer with completion, documentation and inspection. The tooling chapter later in the course covers these in detail; Your First Lisp Programs shows how files are loaded.

Core images and startup files

SBCL keeps a core image: a snapshot of the whole Lisp system, which loads in milliseconds. You can also save your own image. Your personal startup file is ~/.sbclrc; SBCL loads it every time the REPL starts. A common line there loads Quicklisp, the library manager.

LISP
;; ~/.sbclrc (example)
(setf *print-case* :downcase)   ; print symbols in lower case

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the * prompt of the SBCL REPL mean?

    * is the normal prompt. After an error the prompt shows a debugger level such as 0].
  2. 2. In the REPL, what is the variable *?

    *, ** and *** hold the last three results.
  3. 3. Which command runs a Lisp file and exits without opening the REPL?

    --script runs the file non-interactively and exits; --load stays in the REPL afterwards.
  4. 4. Why is it fine for * to be both a function and a variable?

    Common Lisp is a Lisp-2: the operator position is looked up as a function, other positions as variables.

Summary

  • SBCL is the standard free implementation; install it with your package manager.
  • sbcl starts the REPL; the prompt * means ready, 0] means you are in the debugger.
  • *, **, *** hold the last three values; + is the last form.
  • (load "file.lisp"), --load and --script run files.
  • Use rlwrap or an editor integration for line editing.

Next: Your First Lisp Programs