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. 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.
brew install sbcl
sudo port install sbcl
sudo pacman -S sbcl
sudo dnf install sbcl
sudo apt install sbcl
sudo pkgin install sbcl
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.
curl -O https://beta.quicklisp.org/quicklisp.lisp
sbcl --load quicklisp.lisp \
--eval '(quicklisp-quickstart:install)' \
--eval '(quicklisp:add-to-init-file)' \
--quit
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 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! 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 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:
Practical Common Lisp
The gigamonkeys book mentioned above
CLOG
This is a really cool UI kit for building GUIs with common lisp that can run on
computers and phones!
Includine
A library/environment for DSP and composing scores in Lisp. bonkers.
CLiki
The common lisp wiki, full of information
Common Lisp Cookbook
Thorough, helpful articles and a lot of good links.