LISP Reference Material

List Operations

CAR CDR CAAR CADR CDAR CDDR CAAAR CAADR CADAR CADDR CDAAR CDADR CDDAR CDDDR ; Plus 16 more (all combinations of four A's and D's). CONS and . ; Both create a cons cell. LIST ; Creates as many cons cells as needed. ; CDR of last one will be NIL. (NTHCDR n list) (ELT list index) (ELT string index) (LAST list) (LENGTH list) (LENGTH string) (REVERSE list) (REVERSE string) (APPEND list list ...)

Predicates

; Return NIL for false, T for true. LISTP NUMBERP ATOM (MEMBER element list)

Get true/false value from user

(y-or-n-p “string) ; Anything starting with y or n is valid. (yes-or-no-p string) ; Must answer "yes" or "no" exactly.

Equality

EQ EQL EQUAL EQUALP

Arithmetic / Logic

(= n ...), (+ n ...), etc. AND OR ; Short-circuit evaluation. ; Can be used for testing. NOT

Testing

(IF test true-expression false-expression) (COND (test consequent ...) ; Returns result of last consequent ... (T consequent ...)) ; Conventional last test.

Loops

(DOLIST (index list [result]) body) (DOTIMES(index count [result]) body) ; index starts at zero. (DO (index [initial-value [repetitions]]…) (test result) body)

Output

(PRINT string) (PRINT symbol) (PRINT list) (FORMAT do-print? format-string value ...) ; If do-print? is not NIL, print the result and return NIL. ; Otherwise return the formatted string without printing it. ~a ; Print value of a symbol. ~% ; Print a newline.

Variables and Scope

(SETF symbol value) ; Change the value of a symbol. (DEFVAR var value) ; Global variable, can't be redefined. (DEFPARAMETER var value) ; Global variable, can be redefined. (DEFCONSTANT var value) ; Global variable, error to try to change. (DEFUN (parameter ...) body) ; Function definition. (DECLARE (SPECIAL var ...)) ; Dynamic scope. (LET ((var value)...) body) ; Local variables. ; Can be done just before the body ; in either LET or DEFUN.