Setting up a Lisp development environment

So, you might be interested in trying Lisp, but you need a development environment.  I’m afraid at this point some of my personal preferences are going to colour my answers.  I have Linux computers, and I use Emacs as my text editor.  Now, as for Linux, most of what I’m about to say is likely also true of Windows versions of these programs, but I cannot guarantee that because I am actually quite unfamiliar with Windows in any of its incarnations.

The first thing you should do is to download the Common Lisp HyperSpec by following the download directions here.  Install that somewhere in your filesystem.

This brings us to the text editor.  Yes, there are strong feelings about the choice of text editor, particularly among those who choose Emacs vs. those who choose vi.  Really, I’d suggest that Emacs, with its built-in Lisp language, is a natural choice for Lisp development, but there are some vi/vim pointers here.  As I’m writing here about my own experiences, I’m going to describe the Emacs option.

So, you’ve installed Emacs on your operating system of choice.  Now you have to choose a Lisp implementation.  I’m going to assume you want to start out with free software.  Maybe, eventually, you’ll decide that you want to buy a commercial Lisp, but for now, we’ll discuss free implementations.

I have three Lisp implementations installed on my machines.  There’s CLISP, SBCL, and ECL.  CLISP is fine, it has a readline-based REPL, so interactive use is easy, but you’ll quickly find that you don’t actually need to interact directly with the Lisp.  I’ve settled on SBCL for my own Lisp work.  It’s under active development, well-documented, and heavily used, which means external libraries are almost certain to have been tested against SBCL.  ECL is an interesting choice, it can actually compile Lisp code to machine-generated C code.  This way, you can write shared objects in Lisp, and call them from C and C++ code.  I wouldn’t use ECL for everyday projects, but if the C output is desirable, it’s a good choice.

So, now we come to the development environment.  That preferred choice for that is SLIME running in Emacs.  You have to download it separately, it does not usually come bundled with Emacs.  Now, when you start a programming project, you open Emacs and invoke SLIME with the command M-x slime<RET>.  My .emacs configuration for SLIME is here:
 

(setq load-path (append load-path '("/home/neufeld/lisp/slime")))

(setq inferior-lisp-program "sbcl"
      slime-net-coding-system 'utf-8-unix
      lisp-indent-function 'common-lisp-indent-function
      common-lisp-hyperspec-root "file:///home/neufeld/HyperSpec/")

(require 'slime)
(slime-setup '(slime-fancy slime-asdf))

Note that I have set a variable that points to the Common Lisp HyperSpec.  That allows SLIME to look up information when you need it.

Once you’ve started SLIME, your Emacs editor has some very nice features.  One which you will quickly learn to appreciate is that SLIME watches your typing, and fills in the message window at the bottom of the screen with usage information.  For example, if you type the sequence “(sort “, that is an open parenthesis, the word ‘sort’, and a space, then SLIME looks up the documentation for the function ‘sort’, and produces this information immediately on your screen:

(sort sequence predicate &rest args &key key)

If you’ve forgotten the order of parameters, or wonder what the optional keywords are, they’re right here on the screen, you don’t have to stop programming to look up the syntax.  Further, not only does SLIME do this with the built-in functions, but as you write your code and load it into the Lisp system, SLIME recognizes your own functions as well, and produces the same helpful output as you start using those functions.

While SBCL has a fairly hostile REPL (the prompt where you enter your code), you never have to interact with it when programming under SLIME, the SLIME program presents a consistent interface to the user, regardless of the particular Lisp back-end you choose.  That interface includes command history and searching, and is, by default, stored to disc so that your history survives through restarts of the Emacs instance.

So, you now have a working Lisp IDE.  Read the SLIME documentation to find helpful shortcuts, and start programming.

One thought on “Setting up a Lisp development environment

  1. I use emacs under linux too, slime works perfect except that you should install paredit or something like that to remind you which parenthese are you in 😛

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

反垃圾邮件 / Anti-spam question * Time limit is exhausted. Please reload CAPTCHA.