Getting started with Common Lisp
LISP languages have always had a certain appeal to me. In the hands of a LISP professional, it almost seems like magic. On the other hand, it always seemed to be somewhat hard to get started. If you are on a *nix platform, everything works fine and is easy. If you are in a Windows environment, getting started seems to be a more bumpy road.
As always, when starting to look at a new language or environment, the usual questions come up:
- Will it work on Windows and how well?
- What are the limitations of the language?
- Is the compiler / interpreter fast enough?
- Will there be libraries for all the common things I need to do?
- How easy is to get a library and use it?
- Are all the features I expect from a modern programming environment present and working (such as threading, FFI, networking, web programming, GUI programming, etc.)
- Are there enough good documentation to get started and a helpful community to help if you get stuck.
To be fair, those are quite big expectations to start with when looking at any new programming language and environment. I decided to stop worrying too much about the issues and get started with learning the language and starting small.
To get started with a good LISP environment, I chose the following components:
- emacs 24.5 – editor with good support for lisp.
- SBCL 1.2.13 – a good CL implementation.
- SLIME – provides interaction between SBCL and emacs.
- Quicklisp – a package manager for CL.
[title style=”2″]Installing SBCL[/title]
Download and install the latest Windows x64 binaries from sbcl.org.
[title style=”2″]Installing Emacs[/title]
Download and install the latest Windows binaries from gnu.org.
Emacs looks in the following dir for its .emacs init file:
C:\Users\<user>\AppData\Roaming
Upate the .emacs file with the following code:
;; set up package repositories for emacs packages so we can install emacs packages using the built-in
;; package manager.
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.org/packages/")))
;; configure the path to our SBCL installation so emacs knows how to find and load it
(setq inferior-lisp-program "C:/root/programs/SBCL/1.2.13/sbcl.exe")
;; configure emacs so that we can use [shift-arrow keys] to navigate between multiple windows
(windmove-default-keybindings)
;; configure emacs to highlight matching parens, making it easier to see what s-expr we are in
(show-paren-mode 1)
(setq show-paren-delay 0)
[title style=”2″]Installing SLIME[/title]
After updating the .emacs file, restart emacs and use the built-in package manager to install SLIME from the MELPA repository:
M-x package-install RET slime RET
Wait for the package manager to finish. SLIME should now be installed. To start SLIME, enter the following in emacs:
M-x slime RET
You should now have a working SLIME instance running that connects to SBCL.
[title style=”2″]Installing Quicklisp[/title]
Now we need to install Quicklisp, which is a package manager for CL that helps us to install libraries we might need during development.
We can install Quicklisp by downloading the quicklisp.lisp file from quicklisp.org.
After downloading quicklisp.lisp, load the file into your running SBCL interactive session be evaluating:
(load "c:/root/dl/quicklisp.lisp")
then
(quicklisp-quickstart:install)
wait for the installation script to finish. Then eval:
(ql:add-to-init-file)
to make quicklisp load each time SBCL starts up.
If everything went well, you should now have a good starting point to explore CL.