Range Over Iterators 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 into a file, for example, hello-world.lisp, and then use your preferred Common Lisp implementation to load and run it. For example, using SBCL (Steel Bank Common Lisp):

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

Sometimes, we want to compile our programs into a binary that can be executed directly. Here’s how you can create an executable using SBCL.

First, write the following code to a file called hello-world.lisp.

(defun main ()
  (format t "hello world~%"))

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

Then, run this command to generate the executable:

$ sbcl --load hello-world.lisp

You should see a new file named hello-world in your directory. You can run it directly:

$ ./hello-world
hello world

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