# Getting started with Slime

2011-01-30

Slime provides a complete environment for Lisp development with Emacs. It includes a minor mode that enhances lisp-mode, a common lisp debugger (SLDB), an REPL, and an inspector. It supports several CL implementation, including CMUCL, SBCL, Clozure CL, or CLISP.

It comes prepackaged for Aquamacs users, see the Download page on aquamacs.org.

## Basic usage

Start Slime with M-x slime. The first time, a lot of elip files will be compiled on the fly, but the next time it will start much faster. From the on-line help, "This uses the inferior-lisp package to start a Lisp process, loads and starts the Lisp-side server (known as “Swank”), and establishes a socket connection between Emacs and Lisp." The REPL starts CMUCL in my case, because it is the one specified as inferior-lisp-program. It can be changed by adding, e.g.

(setq inferior-lisp-program "/Developer/CCL/scripts/ccl")


in your .emacs file. Should you want to use other flavours of CL implementations, you can just replace the above by something like

(setq slime-lisp-implementations
'((cmucl (lisp "-quiet"))
(sbcl ("/opt/sbcl/bin/sbcl") :coding-system utf-8-unix)
(ccl ("/Developer/CCL/scripts/ccl"))))


The first program will be selected by default, but it can be changed by using M-- M-x slime. In this case, Emacs will prompt you to give the name of the program you want to bind to Slime.

We can also use (append slime-lisp-implementations ...) into the (setq slime-lisp-implementations ...) to add other programs. This is basically what we will do in the next section.

The SLIME User Manual is available as PDF. Here are my very first impression when using Slime.

First, we lauch Slime and just ask to eval (+ 1 3).

Then, we deliberately introduce an error when submitting our code to the REPL, in this case we ask 1-2: it popups an SLDB window saying the variable [1-2] is unbound which means that it has no value bounded to it. Now we can click or select 1: [ABORT] Return to Top-Level. and we're back to the REPL. Another cool thing from using Slime is that you get auto-completion when you are typing into the REPL. For example, let's write a function x -> x^2,

(defun square (x) (* x x))


(We could also use (def square (lambda (x) (* x x))).)

As soon as you start typing defun, you'll get this nice prompt for name and argument:

Let's again introduce an error when typing the function definition, say we wrote (*x x) instead of (* x x). Here is what we get from the SLDB when we run (square 5) at the prompt:

Going back to the REPL, Esc-p two times gives back the previous function definition that we can now correct.

## Slime and Clojure

Slime can be configured to work with Clojure, but you need swank-clojure. A basic setup might look like the one shown below (but I didn't test it myself):

(autoload 'clojure-mode "clojure-mode" "A major mode for Clojure" t)
(require 'swank-clojure)

(setq slime-lisp-implementations
(append slime-lisp-implementations
((clojure ,(swank-clojure-cmd) :init swank-clojure-init))))
`

I found a nice tutorial on setting up Slime and Clojure by watching at Emacs with Clojure, Slime and Swank (by Seth Buntin).

## Articles with the same tag(s):

Emacs Org-mode and literate programming
A modular configuration for Emacs
Common lisp on Mavericks
Scheme and Emacs
Time to lush
Diving into Lisp for statistical computing