Common Lisp Beginner


Home
Links Suggestions About

SBCL Install
Introduction
    In order to be able to run your Common Lisp programs, you need to install a Common Lisp implementation. Due to the sheer number of implementations, it can be quite confusing where to start. Here's a small list of some of the them: SBCL, CLISP, Allegro CL, LispWorks, Clozure, ECL, CMUCL, and many more. Since Common Lisp is standardized, these implementations try to follow the standard, more or less. However, differences do exist, therefore one must be very careful when porting code. Besides the standard, some of them come with extra features. For example, LispWorks is a commercial Lisp implementation that comes packaged with tools you can use to build GUI's. ECL, for example, can be embedded inside an application, so you can let users script it.

    For this tutorial, and in fact for the entire site, we'll be using a Common Lisp implementation called SBCL (Steel Bank Common Lisp). SBCL enjoys a large following, and an active community. It's quite easy to install, and start using. Also, I'm assuming that you're using some kind of a Linux/UNIX system, such as Ubuntu. Let's start installing SBCL.

Install
    The first thing you'll want to do is download a binary of SBCL. If you feel brave, you can download the source code and compile it yourself. Now, mozy on over to the download seciton of the site, and select Linux under x86. Feel free to try another version, however, these tutorials assume Linux under x86.
    Assuming that you've downloaded the file to ~/Downloads, you must extract the files from the archives as follows:

           $ bunzip2 sbcl-1.0.35-x86-linux-binary.tar.bz2
           $ tar xf sbcl-1.0.35-x86-linux-binary.tar
   
    The result of these commands will create a directory ~/Downloads/sbcl-1.0.35-x86-linux. Go to that directory and list all the files, and notice that there is a file called install.sh. Using this file, you can install SBCL for the entire system. Execute "sudo sh install.sh" to begin installation. After the installation is completed type in "sbcl" in the shell, and notice that you are presented with a prompt that begins with "*", as shown in Figure 1.
 
SBCL REPL
Figure 1. 
    This prompt is called the REPL (Read Evaluate Print Loop). This is where you insert Common Lisp code to get evaluated. This is probably a bit different than what you've been using before, where you write code inside a text file, and then run the entire file through a compiler or interpreter. Once you type an expression into the REPL, it gets evaluated. Let's define a function with 2 parameters, and see what happens when we call it. Figure 2 shows the result.

Function definition
  Figure 2.
    First, the add-numbers function was defined by typing out the code, and pressing Enter. As soon as we press Enter, the function definition is loaded into the system. Then, we called add-numbers using two parameters, 1 and 1, which resulted in a return value of 2.

    While the REPL is sufficient for basic editing, it leaves much to be desired. In the next tutorial, we'll be using Emacs and SLIME to create a powerful environemnt for code editing, debugging, evaluation, code formatting, and more.