Clementson's Blog

Bits and pieces (mostly Lisp-related) that I collect from the ether.

December 2008
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Nov  Jan

Understanding SLIME (Using Emacs and Lisp Cooperatively)

Tuesday, December 9, 2008

If you're using Emacs to write Lisp code (either Common Lisp, Clojure, or some dialects of Scheme), you're probably also using SLIME (an Emacs major mode that provides enhanced support for Lisp development). With the recent surge of enthusiasm for Clojure, even more people are starting to use it. However, newcomers (and some experienced Lispers) frequently get confused with how to install and/or use SLIME. So, I've gathered together a bunch of links that (hopefully) will make SLIME easier to come to grips with.

First of all, it should be noted that SLIME has a client-server architecture; the Emacs client portion of SLIME connects to an external Lisp process, which is running a SLIME server. So, SLIME actually consists of two separate components that communicate with one another via an sexp-based communications protocol over a socket:

  1. An Emacs Lisp "front end" that provides certain functionality within the Emacs editor. It is implemented as an Emacs major mode. This is the "SLIME" component.
  2. A "back end" that communicates to the underlying Lisp implementation. This is made up of a standard set of defined interfaces (SWANK) and implementation-specific code (written in the Lisp implementation itself) that implements those interfaces and communicates with the SLIME "front-end". These two (combined) are the "SWANK" component.
Since there is only one SLIME component but multiple SWANK components, it is worth listing out the SWANK "back ends" that are available (most are included as part of the SLIME package; however, the ones with links are available separately): Regardless of the "back end" that you use, the SLIME front-end provides a consistent Emacs interface as well as a consistent set of functionality. Not all "back end" SWANK implementations provide the same level of functionality so some functions will be present as unimplemented "stubs". The following diagram illustrates the basic architecture (taken from Tobias Rittweiler's excellent SLIME presentation in Munich):

Slime/Swank Architecture

In addition to the Emacs Lisp "front-end" of SLIME, there are a number of alternative (but not widely used) front-ends developed by people who didn't want to use Emacs. CUSP is built on the Eclipse platform and runs against the SBCL SWANK back-end. Climacs is a Common Lisp CLIM front-end.

If you are not someone who likes to read documentation, you can avoid 99% of the problems that people have with SLIME by following one simple rule:
Always use the latest CVS version of SLIME with the latest development version of the Lisp implementation.
Dut to the "symbiotic" relationship between SLIME and SWANK, it is not uncommon for changes (in either SLIME or the underlying Lisp) to "break" things. Since the people who develop SLIME are also usually using the latest development versions of CL/Scheme/Clojure, these "breakages" normally get fixed within a day or two. Therefore, if you always upgrade both SLIME and your Lisp implementation simultaneously, you will rarely have any problems.

If you're interested in learning about SLIME, here are some links to documentation that I've found useful:

SLIME Overviews: Movies that describe SLIME and how to use it: Extensions frequently used with SLIME for structured editing of sexp's: I've written a lot of posts about SLIME in the past. I posted first about SLIME in 2003 when I still used ILISP and ELI and thought SLIME was just a flash-in-the-pan (Note: don't rely on my stock picks either!). Here are some of what I consider to be my more informative SLIME-related posts: If you're interested in the concept of using Emacs as a Lisp IDE, you might be interested in reading my paper "Using Emacs as a Lisp IDE" (pdf) from the ILC2003 conference. The paper is really dated now as the Lisp editing modes described in the paper have all largely been replaced by SLIME; however, it might provde some historical background and context if you haven't used a CL editing mode in Emacs before.

emacs Copyright © 2009 by Bill Clementson