Setting Up an SBCL Common Lisp Development Environment With Emacs and SLIME on Debian Linux in 2023

Common Lisp is a powerful and versatile programming language known for its expressive syntax and rich ecosystem of libraries. If you’re a seasoned Linux user, particularly on Debian-based distributions like Debian itself or Ubuntu, setting up a Common Lisp development environment with Emacs using SBCL (Steel Bank Common Lisp) is a straightforward process. I write this article because despite the elegance and functionality of Common Lisp the user base of the language is constantly shrinking.

Don’t forget to join my Discord: https://discord.gg/YbSYGsQYES

Step 1: Install SBCL

The first step in setting up your Common Lisp development environment is to install SBCL. You can do this using the Debian package manager, apt.

Open a terminal and run the following command:

apt update
apt install sbcl

These commands will download and install SBCL along with their dependencies.

Step 2: Install Quicklisp

Quicklisp is a package manager for Common Lisp that simplifies the process of installing and managing libraries and packages.

To install Quicklisp, follow these steps:

  1. Download the Quicklisp installer script:
wget https://beta.quicklisp.org/quicklisp.lisp
  1. Start SBCL by running the following command:
sbcl --load quicklisp.lisp
  1. Install Quicklisp:
(quicklisp-quickstart:install)

Follow the on-screen instructions to complete the installation.

This will set up Quicklisp for your SBCL environment.

Step 3: Set Up Quicklisp

To use Quicklisp for managing Common Lisp packages, you’ll need to load it into your SBCL environment every time you start a new session. You can do this by adding the following code to your ~/.sbclrc file:

#-quicklisp
(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
                                       (user-homedir-pathname))))
  (when (probe-file quicklisp-init)
    (load quicklisp-init)))

This line loads Quicklisp and integrates it with SBCL at every start up.

Step 4: Set Up The IDE: Emacs + SLIME

Install the SLIME package if it is not already installed.

In Emacs run the following commands.

M-x package-install RET

Then type

Install package: slime RET

Emacs is ready to start up SLIME!

M-x slime RET

You find yourself in the SLIME REPL (Read Eval Print Loop).

Now install the “quickproject” package with Quicklisp.

In the REPL use the following command.

CL-USER> (ql:quickload "quickproject")

Install the SLIME helper package as well.

 CL-USER> (ql:quickload "quicklisp-slime-helper")

Add the following lines to the .emacs init file. (Replace the path of your inferior-lisp-program to your Lisp implementation path.)

  (load (expand-file-name "~/quicklisp/slime-helper.el"))
  ;; Replace "sbcl" with the path to your implementation
  (setq inferior-lisp-program "sbcl")

Step 5: Start Developing

With your SBCL Common Lisp development environment set up, you’re ready to start coding. Create a new Lisp source file (typically with a .lisp extension) and write your code. You can use Quicklisp to install and manage libraries and packages as your project requires.

To load and run your code, start SBCL in your chosen text editor or IDE, and use the appropriate command or keybindings to evaluate and execute your Common Lisp code.

Conclusion

Setting up a Common Lisp development environment with SBCL on Debian Linux is a manageable process. With SBCL, Quicklisp, and your preferred text editor or IDE in place, you’ll have a robust environment for writing, testing, and debugging Common Lisp code. Whether you’re a seasoned Lisp developer or just getting started, the flexibility and power of Common Lisp are at your fingertips, ready to help you bring your ideas to life. Happy coding!

Don’t forget to join my Discord: https://discord.gg/YbSYGsQYES

Leave a comment