Use of Common Lisp for CSE 5320/7320

Common Lisp is available on all Alpha machines at SOE.

Execute CLISP by entering “clisp”.  A prompt will be shown:

 

>

At this point, you can type in any valid lisp expression, just like in class. Here are a few examples:

> 3
 
3
 
> nil
 
NIL
 
> (+ (* 2 3) (- 7 1))
 
12

Suppose we type the following Lisp function (functions will be defined in detail later) and save the function in the file ``sample.lisp'':

> (defun simple (x)

   (* x (- x 1)))

You can now execute this function by typing:

> (simple 25)

600

We can now load the file ``hang.lisp'' into the Lisp environment. To load a file, use the load command as follows, putting the file name in quotes.

> (load "hang.lisp")
 
;; Loading file hang.lisp ...
;; Loading of file hang.lisp is finished.
T
>

hang.lisp implements the hangman game.  You can now try playing hangman.  (The objective is to guess the secret word.)

>(hangman)

Notice that when you finish that NIL is displayed.

While you're in Lisp, you can use the dribble function to capture the output to a file. The dribble function takes a file name, in double quotes, as the argument. To close the dribble file, enter (dribble) at the prompt. Everything typed by you and printed by Lisp will be stored in the file until you close the output file.

> (dribble "sample.drib")
 
> (simple 5)
 
20
> (if (= (simple 6) 30)
          t
          nil)
 
T
> (dribble)
 
>

At times, you may enter an invalid Lisp expression or run a program which the Lisp interpreter cannot understand. When this happens, the Lisp interpreter will give you an error message and transfer you to ``debug'' mode, as in the following example.

* add(1,2)
 
*** - EVAL: variable ADD has no value
1. BREAK>
 

In the debugger, if you type ``?'' you will see a list of available debug options. To return from the debugger back to the top-level interpreter, type the ABORT option given to you (in this case ``0'') and the interpreter will continue. You may have to abort out of several levels of errors before returning to the top-level ``*'' prompt.

You can exit Lisp (by typing ``(quit)''). This concludes the introduction to CMU lisp. For further help, consult the manual pages on the system by typing ``man clisp''.

Use the Lisp interpreter to test your homework solutions. Capture the output in a file using dribble, and mail your code and output to the TA. This will be the normal method for turning in homework.