Date: Wed, 08 Jan 1997 21:30:08 GMT Server: NCSA/1.4.2 Content-type: text/html
We will be using an implementation called Allegro CommonLisp (or AllegroCL for short), which is one of the more heavy-duty industrial implementations out there. Allegro CL is sold by Franz Incorporated. (Historical note: the origin of the name Franz was because the product was originally called Franz Lisp, which people thought was pretty darned funny at the time.)
One of the nice things about AllegroCL is that it comes with a nice package for integrating the process of writing and debugging code within a single Emacs session. The basic idea is that you have one "process buffer" open in which Lisp is constantly running, then one or more "editor buffers" each one of which shows a file with some Lisp code in it. The interface allows you to do things like point to a function definition in an editor buffer and send it automatically to the Lisp process, get online entries from the CommonLisp manual, find out where a particular function is defined and automatically pop up an editor window for it, and so on.
It's worth experimenting with this package a bit: it really will make your life a lot easier! I'll try to show you some of the cool features in class too.
Create a file called .emacs in your home directory (if it doesn't already exist) and put the following line in it:
(load "~c341/.emacs")Create a file called .clinit.cl in your home directory and put the following line in it:
(load "~c341/.clinit.cl")Now, when you start up emacs to edit a Lisp file (the Lisp file must have an extension of .cl or .lisp) you will automatically be put into an Emacs mode called "CommonLisp" mode. This mode will do things like balance parentheses and indent your code automatically, and will also allow you to send function definitions directly to the Lisp process.
For example, typing
emacs foo.clwill open the file foo.cl for editing in a special Common Lisp mode buffer that allows you to do things like skip forward and backward by S-expressions, look up the definition of a symbol in the online Common Lisp manual, get a list of what functions call a particular function, and so on.
The following commands work regardless of the mode of your current Emacs buffer:
These commands are special to buffers in "Common Lisp mode," which is the mode assigned to any buffer open to a file with an extension of .cl:
When you are in the Lisp interpreter buffer, C-c C-p recalls the previous expression typed to Lisp, and C-c C-n recalls the next expression (if you are at an earlier one).
Now you can type C-c l to start a Lisp session and put you in it. You can switch back and forth between the editing buffer and the inferior Lisp buffer using C-c l as well.
Emacs will prompt you for several things when you first start a Lisp session: Buffer, Host, Process Directory, Image name, Image arguments. Most of the time, you should just hit return to take the default values on all of these questions.
Go back to edit buffer by C-c l. Type the following code, which simply counts the number of items in a list:
(defun foo(x) (cond ((null x) 0) ((atom x) 1) (t (+ (foo (car x)) (foo (cdr x))))))
Passing this function definition to Lisp either by typing (C-c C-b) (evaluate the entire buffer) or by putting the cursor somewhere within foo's function definiton and typing (ESC C-x) (evaluate a single defun). Either command will send the defun to Lisp interpreter.
Now switch to the Lisp process buffer with: C-c l
Test the function by typing: (foo '(a b c))
When you are done, exit Lisp and Emacs by typing: (exit) and then C-x C-c