Hello World in Lisp

Our first program will print the classic “hello world” message. Here’s the full source code.

(defun hello-world ()
  (format t "hello world"))

(hello-world)

To run the program, save the code in a file with a .lisp extension and then use a Lisp interpreter like SBCL (Steel Bank Common Lisp) to execute it.

$ sbcl --script hello-world.lisp
hello world

Sometimes we’ll want to compile our programs into binaries. With SBCL, you can compile a Lisp file into an executable.

First, save the following additional code to hello-world.lisp:

(defun main ()
  (hello-world))

(sb-ext:save-lisp-and-die "hello-world"
                          :toplevel #'main
                          :executable t)

Then, run the following commands:

$ sbcl --script hello-world.lisp
$ ls
hello-world       hello-world.lisp

We can then execute the built binary directly.

$ ./hello-world
hello world

Now that we can run and build basic Lisp programs, let’s learn more about the language.