Common Lisp Tutorial 0: Setup
by NMunro
Introduction
It’s been a couple of lessons in and I had not yet shown how to get a development environment set up, my bad! It’s about time that I corrected that oversight as getting the Common Lisp toolchain up and running on my machine was no easy thing, there was a lot of missteps, a lot of misunderstandings and generally not a fun time, however, having been doing this for a while now, I’m pretty certain I have an easy setup guide for the new Common Lisper.
Please note, these instructions are generally aimed at the Mac, however, most commands can be easily switched to Linux distros with few changes, the only major one being emacs-plus is a macos specific package, regular emacs should be fine for most Linux systems but I will provide Linux commands where they differ from the Mac.
Sorry Windows users, I just don’t work with it and have no way to test it, however, if you have something you can contribute to this guide let me know!
Installing a Common Lisp interpreter
First and foremost a Common Lisp interpreter is needed, now, there’s a few to choose from: ABCL, Clisp, CCL, SBCL, LispWorks, however I typically use SBCL, it’s kept up to date every few weeks and integrates without much effort, making it a nice developer experience. Once thing to bear in mind though is that the interpreter doesn’t have readline turned on by default, so it’s a good idea to install rlwrap and use that to enable history support in the interpreter. SBCL also has a package (asdf) installed by default which makes developing and testing Lisp code much easier and means you do not need to explicitly install these.
Installation on Mac (via homebrew)
$ brew install rlwrap sbcl
Installation on Linux
$ sudo <dnf/apt/zypper> install rlwrap sbcl
Installing quick lisp
Secondly, installing Quicklisp is practically essential, while SBCL has asdf which helps resolve local dependencies, Quicklisp is the de-facto package repository for Common Lisp, so if you want to work with third party code and use other peoples libraries you will need Quicklisp.
Installation is simple and well worth it!
$ curl -O https://beta.quicklisp.org/quicklisp.lisp
$ sbcl --load quicklisp.lisp
* (quicklisp-quickstart:install)
* (ql:add-to-init-file)
* (exit)
Installing Emacs
Emacs is hands down the best way to work with Lisp, it’s hard to explain why until you get into the habit of it, but I shall try… Unlike other programming languages where you write code and run it via a terminal or the click of a button Emacs and Lisp appear to be in a symbiotic relationship with one another. When you have code on screen, you can press a key keystrokes and the code runs, either the whole file, just the highlighted section and you can get results in the editor. This means you can test code much more rapidly than running a program as a whole.
Macos (with emacs-plus)
$ brew tap d12frosted/emacs-plus
$ brew install emacs-plus
Note: You will need to create an alias (not a symlink) in /Application from /usr/local/opt/emacs-plus@2x (27 at time of writing)
Linux
$ sudo <dnf/apt/zypper> install emacs
Installing Doom Emacs (optional)
Doom Emacs is the distribution of Emacs I prefer (I am a stubborn martian vimmer, I guess), if you do not like Vim, or are not used to it, I hesitate suggesting that you learn the Vim way, unless it’s been on your todo list for a while.
Please only commit to this step if you are already, or willing to learn Vim modal editing.
$ git clone --depth 1 https://github.com/hlissner/doom-emacs ~/.emacs.d
$ ~/.emacs.d/bin/doom install
Installing my config (optional)
While Doom Emacs is damn near perfect, I have found I needed to add a few packages and make a few tweaks to my setup, if you find it useful please feel free to use my config, although, do make sure you delete ~/.doom.d
first, otherwise the git clone wont work.
$ git clone https://github.com/nmunro/.doom.d
$ ~/.emacs.d/bin/doom upgrade