Colorado State University

How to Run Allegro Common Lisp



Getting Started

Allegro Common Lisp is in /usr/local/allegro4.3.1/bin; make sure that this directory is in your load-path. Additionally, Allegro Common Lisp (ACL) will load an initialization file if one is available. As a start, copy .clinit.cl into a directory from which you will run ACL; ACL will look for an .clinit.cl file when it is initiated.


Running Allegro Common Lisp from the OS Prompt

You should use any of the Sun Ultras to run ACL (look at the ~info/machines   file for a complete listing of the Sun Ultra machines of general access).

To start lisp, simply type class-lisp or pb_clim2xm_composer at the prompt. pb-clim2xm-composer is the full Common Lisp system complete with CLOS (object system), CLIM (Interface Manager) and Composer (enhanced debugger); class-lisp is a stripped down version containing only the basic language definition and CLOS. Unless you need CLIM, please use class-lisp as it will load faster and use less memory than the full version.

As ACL starts up, it will print the following:

  18 -> class-lisp
  Allegro CL 4.3.1 [SPARC; R1] (9/15/97 11:49)
  Copyright (C) 1985-1997, Franz Inc., Berkeley, CA, USA.  All Rights Reserved.
  CS440 functions loaded:
  
     emacs         vi
     sdraw         sdraw-loop      scrawl
     dtrace        duntrace
  ;; Optimization settings: safety 1, space 1, speed 1, debug 2.
  ;; For a complete description of all compiler switches given the
  ;; current optimization settings evaluate (EXPLAIN-COMPILER-SETTINGS).
  USER(1): 

The final line, USER(1): is the prompt; you can enter lisp expressions at this point. The prompt tells you what package you are currently within. Since, you do not know yet about package, don't worry about them yet. The default package, as you will see, is USER. The prompt also indicates how many commands you have entered since beginning the session. Later, you will see the prompt is also used to indicate when you have entered the debugger.


Running Editors from Allegro CL

The less elegant, more brute force, and easier way to combine editing and ACL is to start ACL from the Unix Shell and them invoking either Emacs or vi from within ACL. This lets you start a editor session completely independent of Lisp, modify a file, exit the editor and load the file.

To do this, you must already have placed the .clinit.cl file at the directory from which you will be running ACL. This initialization file loads functions for calling vi or Emacs from within ACL. As one would expect, the emacs function takes a filename as an argument and calls Emacs to edit that filename; upon exiting Emacs, you will be asked whether the filename should be loaded into your ACL session. The vi function works similarly. For example, the following shows how to edit and load a file called ``test.lisp'' while in an ACL session:

     USER(1): (emacs "test.lisp")
     Do you want to load test.lisp?yes
     ; Loading /s/bach/a/class/cs440/test.lisp.
     T
     USER(2): 


Running Allegro Common Lisp from Emacs

A much more powerful alternative is to run ACL within one window of an Emacs window. Since this is the preferred way of running Lisp, a separate handout has been compiled on how to do this. It includes a tutorial which will give you hands-on experience with the various features of the emacs to lisp interface.


The Debugger

Because Lisp is interpreted, most of your bugs will be discovered at run-time. Some bugs are fatal, meaning that they cause errors that put your process into the debugger. Once there, you can inspect the status of your program and figure out what went wrong.

For example, say we're defining a function that adds one to every number in a list. Our first effort to define it produces:
(defun incr (L) (cons (+ 1 (first L)) (incr (rest L))))
We load it in and run it as follows:

     USER(8): (incr '(1))
     Error: EXCL::+_2OP: `NIL' is not of the expected type `NUMBER'
       [condition type: TYPE-ERROR]
     [1] USER(9): 
The debugger prints the error message and then adds [1] to the front of the prompt to indicate that you are now in the debugger and are dealing with a first level error. To discover where the error occurred in the program, we type :bt which shows us the contents of the stack.
     [1] USER(9): :bt
     Evaluation stack:
     
     + <-
       INCR <- INCR <- EVAL <- TPL:TOP-LEVEL-READ-EVAL-PRINT-LOOP <-
       TPL:START-INTERACTIVE-TOP-LEVEL
So now we know that the problem is in the s-expression starting with + after a recursive call to incr. The first argument is 1, which should be fine, but the second is a call to (first L), which seems to have returned nil. We can check its arguments with another debugger command, :local, which prints the value of all of the local variables at this point in the stack.
     [1] USER(10): :local
     Interpreted lexical environment:
     L: NIL
     Compiled lexical environment:
     0(REST): EXCL::ARGS: (1 NIL)
     1(LOCAL): L: NIL
     2(LOCAL): :UNKNOWN: (1 NIL)
     3(LOCAL): :UNKNOWN: NIL
     4(LOCAL): :UNKNOWN: #
     5(LOCAL): :UNKNOWN: (NIL)
     6(LOCAL): :UNKNOWN: 0
     7(LOCAL): :UNKNOWN: 0
     8(LOCAL): :UNKNOWN: 0
     9(LOCAL): :UNKNOWN: 0
     10(UNKNOWN): :UNKNOWN: NIL
This confirms that the second argument to the + is nil and shows that the current value of L is nil as well.

So it looks like we need to add a check for a null list before proceeding with the recursion. So we change the code to
(defun incr (L) (and L (cons (+ 1 (first L)) (incr (rest L))))) We run it again and find:

     [1] USER(12): (incr '(1))
     (2)
     [1] USER(13): :pop
     USER(14): 
So the code appears to work fine. To get out of the debugger, type :pop.

All debugger commands are preceded by ":". To find out the full list of commands, type :help at the debugger prompt. These really are just the basics. Others let you traverse the stack (levels of recursion) and check on values of variables as you go, for example.


Exiting Allegro Common Lisp

Once you are done with an ACL session, you can finish the session by typing the function (exit). If ACL was started from the shell command line, then this will return you to the operating system. If it is run from within Emacs, then it will leave the window open and display a series of messages indicating that both ACL and the ACL to Emacs interface has been shut down. You can now simply quit Emacs with the key strokes C-x C-c.



Written by Ross Beveridge and Adele Howe
Last updated on 9/18/97

Comments: howe@CS.ColoState.EDU ; ross@CS.ColoState.EDU
Copyright © 1998: Colorado State University, CS Department. All rights reserved.