COMMON LISP HELP DEBUGGING, TOP-LEVEL OPTIONS, FORMATTING OUTPUT, COMMON ERRORS RKHill; Last update 13 February, 2001. -------------------------------- To load some code written in an editor :ld filename OR (load "filename") To get rid of all those error messages, by breaking out of the debug levels" :reset To see the values of parameters passed and returned to and from a function f :trace f OR (trace f) To step through a function f :step f OR (step f) To find out a lot about a form :inspect form OR (inspect form) When in a break caused by an error, you can use setq to set a variable to a different value, and then reevaluate the expression that caused the error :prt Example: USER(32): (/ 100 x) Error: Attempt to divide 100( by zero [condition type: DIVISION-BY-ZERO] [1] USER(33): (setq x 2) 2 ---> [1] USER(34): :prt USER(35): (/ 100 X) ;; :prt evaluation 50 -------------------------------- Other useful top-level commands for bookkeeping and so forth: :pwd shows the current directory :cd dir-name changes to the directory dir-name :zoom prints the evaluation stack :history shows the recent forms and commands :help tells you about top-level commands Some top-level variables that can be set to control display and evaluation *print-length* how much of form shown before "..." is used *prompt* change the prompt -------------------------------- Formatting Output ( format stream control-string arg* ) Returns, to the stream, the args, formatted according to the control-string. If stream is 't,' returns to the terminal screen. Format directives for the control-string: ~A Prints the arg as ASCII ~S Prints the arg as ASCII, but with escape characters ~nA Prints the arg as ASCII in a field of width n ~nD Prints a decimal number in a right-justified field of width n ~n,iF Prints floating-point arg in a field of n+1 with i decimal places ~T Prints a tab ~% Skips to new line ~& Skips to new line conditionally (if not following new line) ~{dir} Prints each element in list arg according to directive inside Example: (format t "Yo!~3A~5D~S~T~8,6F~S" #\@ 902 (cons 'j NIL) (sqrt 2) #\@) ==> Yo!@ 902(J) 1.414214#\@ NIL -------------------------------- Common Errors 1. Trying to evaluate a nested form (into a function, for example): ((+ 31 94) 8 79) Will not produce 212! The 125, which becomes the car of the list, is not a function. 2. Omitting the result from a "dolist": (let ((nncount 0)) (dolist (i L) (if (not (null i)) 1+ i))) Does not return a count of the non-nil elements of L! What you want is: (let ((nncount 0)) (dolist (i L count) <--- NOTE!!! (if (not (null i)) 1+ i))) 3. Assuming "cons" (or "append") is destructive: (dolist (i L newL) (if (null i) (cons 'X newL) (cons i newL))) Will not return a new list with X replacing nil elements! It just returns newL, the original newL. This task should be done with "mapcar", anyway.