How to Run Allegro Common Lisp |
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.
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):
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-LEVELSo 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: #This confirms that the second argument to the + is nil and shows that the current value of L is nil as well.5(LOCAL): :UNKNOWN: (NIL) 6(LOCAL): :UNKNOWN: 0 7(LOCAL): :UNKNOWN: 0 8(LOCAL): :UNKNOWN: 0 9(LOCAL): :UNKNOWN: 0 10(UNKNOWN): :UNKNOWN: NIL
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.
Comments:
howe@CS.ColoState.EDU
;
ross@CS.ColoState.EDU
Copyright © 1998: Colorado State University, CS Department.
All rights reserved.