Getting Started with Common Lisp in 2023
So youβve written hundreds of thousands of lines of Emacs Lisp and you want to use that dark power for good. Youβve tried every scheme implementation you can find, but they all feel kind of hollow and empty in a way you canβt explain.[1] Youβve tried Clojure but youβve never managed to get past the βsetting up your first Clojure projectβ stage because there are too many choices and they all seem to be the wrong choice for different reasons. Well, thatβs a remarkable fucking coincidenceβ¦ this postβs for you!
If that doesnβt sound like you Iβve got some good news and some bad news. Good news: you arenβt me. Bad news: this post is not for you. On reflection, I think thatβs two pieces of good news.
1. Install Steel Bank Common Lisp
There are many implementations of the common lisp specification. sbcl is lovely. Itβs open source and actively maintained. It will serve you well on nearly any system you have. Letβs use that.
Itβs in most package repositories under the name sbcl.
# with homebrew on mac or linux
brew install sbcl
# or, with macports on mac
sudo port install sbcl
# or, with pacman on arch linux/steamos 3
sudo pacman -S sbcl
# or, dnf on fedora
sudo dnf install sbcl
# apt on ubuntu/debian/raspberry pi os
sudo apt install sbcl
# netbsd
sudo pkgin install sbcl
# ... etc
There are .msi installers for Windows available on sourceforge.
2. Install Quicklisp
There are many ways to handle packaging in the common lisp world. Quicklisp has been around for over a decade. Itβs ubiquitous and itβs reliable, so letβs use that.
# get quicklisp
curl -O https://beta.quicklisp.org/quicklisp.lisp
# install it
sbcl --load quicklisp.lisp \
--eval '(quicklisp-quickstart:install)' \
--eval '(quicklisp:add-to-init-file)' \
--quit
# remove the quickstart script
rm quicklisp.lisp
Youβll get a prompt telling you itβs going to add something to your \~/.sbclrc, thatβll make sure quicklisp can be used any time you want to install a dependency. You can install libraries by running sbcl --eval '(ql:quickload "package-name").
3. Get your text editor ready
Yeah, letβs get all those swanky text editor features set up. This will depend on what editor youβre using.
Emacs
This is how Iβve configured Emacs to use sbcl and SLIME[2] as my inferior lisp:
(use-package inf-lisp :config (setq inferior-lisp-program "sbcl"))
(use-package slime :elpaca t
:config
(setq slime-contribs '(slime-fancy slime-autodoc slime-asdf slime-quicklisp)))
Iβm using use-package and elpaca to manage my packages. You can use :ensure t here instead if you are using the vanilla emacs package management. If youβre using something else, youβll need to do a little research.
M-x slime will now start a lisp REPL. You can C-x C-e to send the last expression to the repl to be evaluated, C-c C-c to send the current defun. Itβs really powerful and cool! It makes Common Lisp almost as fun to write as emacs lisp[3]! Check out the manual when you are ready to know more.
The quicklisp contrib here lets you load systems into the repl by pressing , then typing ql then hitting enter and typing the name of the package. Itβll show you all the packages it knows about, even ones you havenβt installed. Itβs really fast, wow.
Visual Studio Code
Iβve heard good things[4] about ALIVE, which is a SLIME-like for Visual Studio Code.
You aready have Quicklisp installed so you can run this to get all the dependencies:
sbcl --eval '(ql:quickload "bordeaux-threads")' \
--eval '(ql:quickload "usocket")' \
--eval '(ql:quickload "cl-json")' \
--eval '(ql:quickload "flexi-streams")' \
--quit
Then you can install the extension from within Visual Studio Code and you should be good to go! Thereβs a LOT of information about using Alive on the Common Lisp cookbook page about it.
If you run into any trouble, check ALIVEβs overview on the Visual Studio Marketplace.
4. Start writing some damn lisp!!!!
If youβre looking for a good book to get started, I donβt believe thereβs anything better than the gigamonkeys book. I first went through it about 15 years ago and had a great time, though I didnβt understand much of what I was doing back then. Iβm just about to go through it again. Join me!
If youβre knew to lisp altogether, the mini-tutorials on lisp-lang.org will be helpful for you.
Iβd recommend keeping all your source code in \~/common-lisp/. That folder is automatically picked up by asdf and quicklisp so youβll be able to more easily define and use your own systems when the time comes. Thatβs a topic for another blog post.
Resources of interest
Here are some cool things to know about:
The gigamonkeys book mentioned above
This is a really cool UI kit for building GUIs with common lisp that can run on computers and phones!
A library/environment for DSP and composing scores in Lisp. bonkers.
The common lisp wiki, full of information
Thorough, helpful articles and a lot of good links.
-
Except CHICKEN, of course, because it rules. β©οΈ
-
In the original version of the post, I had a bit here about overriding the
slime-words-of-encouragementto remove the one that calls you brother, but then a few hours later the maintainer of SLIME pushed a commit that deletes it!I still like some of the ones I added, though:
(mapc (apply-partially #'add-to-list 'slime-words-of-encouragement) '("Come on, let's go." "Vamos." "A ver." "You'll always find me in the REPL at parties." "OK, let me have it."))It keeps all the originals and adds these few extra silly ones. β©οΈ
-
Not quite, though. Nothing is as fun to write as emacs lisp. Emacs lisp is literally the best programming language in the world.
The example of how Iβve configured SLIME is trimmed down for the post. The full version has a lot of extra fancy stuff. You can see here: docfiles/setup β©οΈ
-
The βgood thingsβ are that it:
- exists
- works