Skip to main content

Hello World (first programs) · Beginner · 14 min

Hello World in Common Lisp with SBCL: the REPL and a native executable

By Padding · Updated 18 Nov 2026
Debian (clfoundation/sbcl:2.6.10 image) · SBCL 2.6.10

You will install SBCL 2.6.10, print Hello World at the Common Lisp REPL and from a script, define and redefine a greet function, and build a standalone executable that reads your name.

On this page

Common Lisp is one of the oldest programming languages still in daily use, standardised by ANSI in 1994, and it has an unusual idea at its centre: your program is written as lists. Every piece of code is a list in parentheses, called an s-expression, and the first item names what to do. (+ 1 2) adds one and two. Because code is plain list data, a Lisp program can build code, inspect it and run it, which is where Lisp's macros come from.

The second idea is the image. When you start a Lisp, you get a running world of functions and data. You add to it and change it while it runs, one form at a time, instead of the usual edit, compile, restart loop. When you are happy, you can save that whole world to disk as a program.

This tutorial uses SBCL (Steel Bank Common Lisp), a widely used free, open-source Common Lisp implementation. SBCL compiles every function to native machine code as you define it, even ones you type at the prompt, so Lisp code runs fast without a separate build step. You install SBCL, print Hello World at the REPL and from a script, define a greet function and change it inside a running Lisp, then go one step further: read a name from the keyboard and save the program as a standalone executable.

Step 1 · Install SBCL

Pick the route for your system. The current release is SBCL 2.6.10, from 29 October 2026.

On Ubuntu 26.04 or Debian, the quickest route is apt. Ubuntu 26.04 packages SBCL 2.6.0, which is fine for everything in this tutorial and gets security updates with the rest of your system:

Bash
sudo apt update
sudo apt install -y sbcl

For the exact current release on an x86-64 Linux machine, use the official binary from the SBCL project. It is a download of roughly 10 MB, which matters if you are on prepaid mobile data. Download it into a fresh temporary folder, unpack it and run its installer:

Bash
sudo apt install -y curl bzip2
cd "$(mktemp -d)"
curl -fL -o sbcl.tar.bz2 https://downloads.sourceforge.net/project/sbcl/sbcl/2.6.10/sbcl-2.6.10-x86-64-linux-binary.tar.bz2
tar -xjf sbcl.tar.bz2
cd sbcl-2.6.10-x86-64-linux
sudo sh install.sh
cd ~

install.sh copies the sbcl program to /usr/local/bin and its core files to /usr/local/lib/sbcl. A hand-installed SBCL gets no apt updates; to upgrade, repeat these commands with a newer version number from the SBCL download page at sbcl.org.

On macOS, run brew install sbcl. On Windows, the simplest way to follow this tutorial is WSL (Windows Subsystem for Linux): run wsl --install in an administrator PowerShell, restart, open the Ubuntu terminal and use the Linux steps above. Every command below then works as written. SBCL also has a native .msi installer for x86-64 Windows on its download page, but the commands in this tutorial are written for a Linux or macOS shell: on native Windows the cat > file lines, ~, mkdir -p, the \` line continuations, `ls -lh, rm -rf and < /dev/null do not work, --eval '...' quoting fails in Command Prompt, and the saved executable needs the name hello.exe to run.

Now check the version:

Bash
sbcl --version

Check it worked

sbcl --version prints SBCL 2.6.10, or SBCL 2.6.0 followed by a Debian suffix if you used apt. If you get command not found right after the binary install, your shell may have remembered the old lookup: open a new terminal or run hash -r. If it still fails, check that echo $PATH lists /usr/local/bin; if it does not, add export PATH="/usr/local/bin:$PATH" to ~/.bashrc (or ~/.zshrc) and open a new terminal.

Step 2 · Say Hello World at the REPL

Start SBCL with no arguments:

Bash
sbcl

SBCL prints a short banner and then its prompt, a single *. Type each line after the * and press Enter:

Text
* (format t "Hello, World!~%")
Hello, World!
NIL
* (+ 1 2 3)
6
* (format t "~a plus ~a is ~a~%" 2 3 (+ 2 3))
2 plus 3 is 5
NIL

Here is what each part means:

  • (format t "Hello, World!~%") is a list of three items. The first, format, is the function to call. t as the destination means "standard output", your terminal. The string is a template.
  • ~% inside the template is a format directive that prints a newline. Format directives start with a tilde. Without ~%, the next thing printed would start on the same line.
  • NIL is the value format returned. The REPL reads a form, evaluates it, prints the result, and loops, which is where the name REPL comes from. Printing the greeting was a side effect; NIL, Lisp's word for "nothing" and for false, is the result.
  • (+ 1 2 3) shows prefix notation: the operator comes first, and + takes any number of arguments.
  • ~a prints the next argument in readable form. The third line fills three ~a slots with 2, 3 and the result of (+ 2 3). That inner list is evaluated first, then its value is passed to format.

Leave the REPL with (exit) or Ctrl+D. The SBCL prompt has no line editing or history of its own. If the arrow keys print ^[[A, install rlwrap (sudo apt install rlwrap) and start the REPL with rlwrap sbcl instead.

You can also evaluate a form from your shell without opening the REPL:

Bash
sbcl --noinform --non-interactive --eval '(format t "Hello, World!~%")'

--noinform hides the banner, --eval evaluates one form, and --non-interactive makes SBCL quit afterwards instead of waiting at the prompt. Values are not printed here, because only the REPL prints them.

Check it worked

At the REPL, the first form printed Hello, World! and then NIL, and the last printed 2 plus 3 is 5. The shell command printed Hello, World! on its own, with no banner and no NIL.

Step 3 · Run a script with sbcl --script

Make a throwaway folder for this tutorial and a file called hello.lisp:

Bash
mkdir -p ~/hello-lisp-demo
cd ~/hello-lisp-demo
cat > hello.lisp <<'LISP'
;; hello.lisp: print one greeting
(format t "Hello, World!~%")
LISP
sbcl --script hello.lisp

The file has two lines. The first starts with semicolons, which make it a comment: Lisp ignores everything from ; to the end of the line, and two semicolons is the convention for a comment on a line of its own. The second is the same format call you typed at the REPL.

sbcl --script hello.lisp starts SBCL without the banner, reads the file one form at a time, compiles and evaluates each form, and quits at the end of the file. It also skips your personal start-up files and turns off the interactive debugger, so an error prints a message and stops the script instead of waiting for you to type.

Check it worked

The last command prints Hello, World! and returns you to the shell prompt.

Step 4 · Define a greet function with defun

Write a second file that defines a function and calls it twice:

Bash
cd ~/hello-lisp-demo
cat > greet.lisp <<'LISP'
(defun greet (name)
  "Print a greeting for NAME."
  (format t "Hello, ~a!~%" name))

(greet "World")
(greet "Amara")
LISP
sbcl --script greet.lisp

Line by line:

  • (defun greet (name) starts a function definition. defun means "define function", greet is its name, and (name) is the list of parameters: one, called name.
  • "Print a greeting for NAME." is a documentation string. It is optional; at the REPL, (documentation 'greet 'function) gives it back.
  • (format t "Hello, ~a!~%" name)) is the body. The ~a slot is filled with the value of name. The last two closing parentheses end the format call and then the defun. The value of the last form in the body is what the function returns.
  • (greet "World") and (greet "Amara") call the function. A call to your own function looks exactly like a call to a built-in one.

Count the parentheses only if something breaks. Lisp programmers read the indentation and let the editor balance the brackets; most editors highlight the matching parenthesis when the cursor is next to one.

Check it worked

The script prints two lines: Hello, World! and Hello, Amara!.

Step 5 · See that code is a list

Since a Lisp form is a list, you can build one as data and then run it. Create forms.lisp:

Bash
cd ~/hello-lisp-demo
cat > forms.lisp <<'LISP'
(defun greet (name)
  (format t "Hello, ~a!~%" name))

(defparameter *form* (list 'greet "Lisp"))

(format t "The form is ~s~%" *form*)
(format t "Its first item is ~a~%" (first *form*))
(eval *form*)
LISP
sbcl --script forms.lisp
  • (defparameter *form* ...) creates a global variable called *form*. The asterisks around the name are a naming convention for global variables, not syntax.
  • (list 'greet "Lisp") builds a list of two items. The quote in 'greet means "the symbol greet itself", not "call greet". Without the quote, Lisp would try to evaluate greet as a variable.
  • ~s prints a value the way you would type it back in, so the string keeps its double quotes. Symbols print in capitals because the Lisp reader turns unquoted names into upper case when it reads them.
  • (first *form*) takes the first item of the list, the symbol GREET.
  • (eval *form*) hands the list to the evaluator, which treats it as code and calls greet with "Lisp".

Macros take this further: a macro is a function that receives code as lists and returns new code, which is then compiled. Many parts of Common Lisp you will meet later, such as loop and defun itself, are macros.

Check it worked

The script prints The form is (GREET "Lisp"), then Its first item is GREET, then Hello, Lisp!.

Step 6 · Change a function inside a running Lisp

In the REPL you can load a file, then redefine one of its functions while the Lisp keeps running, and every later call uses the new version. Try it:

Bash
cd ~/hello-lisp-demo
sbcl
Text
* (load "greet.lisp")
Hello, World!
Hello, Amara!
T
* (defun greet (name) (format t "Good morning, ~a.~%" name))
WARNING: redefining COMMON-LISP-USER::GREET in DEFUN
GREET
* (greet "Amara")
Good morning, Amara.
NIL
* (compiled-function-p #'greet)
T
* (exit)

load reads and runs the file, which prints its two greetings and returns T (true). The new defun replaces greet in the running image; SBCL warns that it is redefining a function, which is expected here. #'greet means "the function named greet", and compiled-function-p returning T shows that SBCL already compiled your one-line definition to machine code, with no build step from you. In larger programs, this is how Lisp developers fix a bug in a server without restarting it, usually from an editor connected to the running Lisp.

The same session as one shell command, with each --eval run in order:

Bash
cd ~/hello-lisp-demo
sbcl --noinform --non-interactive \
  --load greet.lisp \
  --eval '(defun greet (name) (format t "Good morning, ~a.~%" name))' \
  --eval '(greet "Amara")' \
  --eval '(format t "Compiled: ~a~%" (compiled-function-p (function greet)))'

(function greet) is the long form of #'greet.

Check it worked

You see Hello, World! and Hello, Amara! from the loaded file, then Good morning, Amara. from the new definition, then Compiled: T. A redefinition warning may appear among them; it goes to the error stream and is harmless.

Step 7 · Read a name and build a standalone executable

Now write a small program that asks for a name, and save it as an executable that runs without SBCL installed. Create hello-app.lisp:

Bash
cd ~/hello-lisp-demo
cat > hello-app.lisp <<'LISP'
(defun main ()
  (format t "What is your name? ")
  (finish-output)
  (let ((name (read-line *standard-input* nil "")))
    (if (string= name "")
        (format t "Hello, World!~%")
        (format t "Hello, ~a!~%" name))))
LISP
  • (defun main () defines a function with no parameters. It will be the program's entry point.
  • (finish-output) pushes the question to the terminal now. Output is buffered, and without this line the prompt might not appear before the program waits for input.
  • (read-line *standard-input* nil "") reads one line from the keyboard. The nil says "do not raise an error at end of input" and "" is the value to return in that case, so the program also works when no input arrives.
  • (let ((name ...)) ...) binds the line to a local variable called name for the rest of the form.
  • (if (string= name "") A B) runs A when the name is empty and B otherwise. string= compares two strings.

Build the executable. This loads the file into a fresh SBCL, then saves the whole image, with main as its starting point, to a file called hello:

Bash
cd ~/hello-lisp-demo
sbcl --noinform --non-interactive \
  --load hello-app.lisp \
  --eval '(sb-ext:save-lisp-and-die "hello" :executable t :toplevel (function main))'
ls -lh hello

sb-ext:save-lisp-and-die is SBCL's own function, in its sb-ext package of extensions, and the name says what happens: the image is written to disk and that SBCL process ends. :executable t puts the SBCL runtime and your image in one file, and :toplevel names the function to call when it starts. The file is large, tens of megabytes, because it carries the whole Lisp with it, compiler included.

Run it and type a name:

Bash
./hello

Or give it the name on standard input, and try it with no input at all:

Bash
cd ~/hello-lisp-demo
echo "Amara" | ./hello
./hello < /dev/null

The executable runs on other machines with the same operating system and processor type, even without SBCL installed. Build it on x86-64 Linux and it runs on x86-64 Linux, not on macOS or an ARM board.

Check it worked

ls -lh shows a file called hello of several tens of megabytes. Typing Amara at the prompt prints Hello, Amara!. The piped run prints What is your name? Hello, Amara! on one line, because the typed name is not echoed, and the run with no input prints What is your name? Hello, World!.

Step 8 · Learn the mistakes beginners hit, and clean up

These come up in almost everyone's first week of Lisp:

  • A missing closing parenthesis. In a script you get an error mentioning end of file, because the reader reached the end of the file still inside a list. At the REPL, nothing happens when you press Enter, because SBCL is waiting for the rest of the form. Type the missing ) and press Enter again.
  • The debugger. A typo such as (gret "Amara") at the REPL prints The function COMMON-LISP-USER::GRET is undefined., a numbered list of restarts and a prompt like 0]. You are in the debugger, not stuck. Type the number shown next to ABORT and press Enter to return to the * prompt.
  • Single quotes for strings. 'hello' is not a string in Lisp. A single quote means "do not evaluate the next thing". Strings always use double quotes.
  • Forgetting ~%. Without it, the next output, or your shell prompt, lands on the same line as your greeting.
  • Text in other languages and scripts. SBCL strings hold Unicode, so (greet "Chinedu") and names in Amharic or Arabic script work, as long as your terminal and the file use UTF-8, which is the default on current Linux and macOS systems.

When you need libraries, Common Lisp programmers use Quicklisp, which downloads and loads thousands of open-source libraries from inside the REPL. Install it once you have a project that needs one.

Where Common Lisp is used today: research software and artificial intelligence work, where it has a long history; symbolic computing, such as the Maxima computer algebra system, which is written in it; and some trading, scheduling and planning systems that value changing a running program without stopping it.

To remove everything this tutorial created:

Bash
rm -rf ~/hello-lisp-demo

If you installed SBCL with apt, sudo apt remove sbcl removes it. For the binary install, delete /usr/local/bin/sbcl and the /usr/local/lib/sbcl folder.

Check it worked

ls ~/hello-lisp-demo reports that there is no such file or directory.

Next steps

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.