Quick Lisp Review


A quick survey of the Lisp functions that I expect you to be already familiar with. Look them up in your Lisp reference if it is not clear what they do.

Numeric Functions

*, +,-,/ - returns product, sum, difference, or quotient of numbers. (/ (+ 2 2) (- 3 1)) ==> 2

sqrt, expt, min, max. (min -1 2 -3 4 -5 6) ==> -5

List Functions

first, second, third, ..., tenth - returns indicated element

(third '(A B C D)) ==> C

rest, last, nth, length Note that nth starts counting at 0, not 1. (nth 2 '(A B C D)) ==> C

cons, append, list - basic list construction functions

Predicates

Type-checking Predicates: listp, numberp, integerp, atom, stringp (etc.)

Numeric Predicates: evenp, oddp, =, <, >, <=, >=

General Predicates: null, equal, eq. The basic rule is that "eq" may not work for lists or strings.

(equal '(A B) (cons 'A '(B))) ==> t

(eq '(A B) (cons 'A '(B))) ==> NIL

Logical Predicates: and, or, not

(not (and (= 7 (+ 2 5)) (evenp 8))) ==> NIL

Special Forms

Special forms are used for side effects, and do not follow the normal Lisp rule of evaluating all the arguments before applying the function to the results.

setq (or setf) - assigns a value to a variable. Setf can also be used in more powerful ways, but be careful.

" ' " (or quote) - returns argument literally

defun - defines a function

if, cond, case - conditional operators. There are more.

Function Application

mapcar, apply, funcall Note that special forms or user-defined macros cannot be used here; only true functions. So (mapcar #'if List) is illegal.

(mapcar #'evenp '(1 2 3 4)) ==> (NIL t NIL t)

(apply #'+ '(1 2 3 4)) ==> 10

(funcall #'+ 1 2 3 4) ==> 10

find-if, find-if-not, remove-if, remove-if-not - Good for searching lists. See also find and remove, which can take functions optionally as :key and :test arguments.

(find-if #'oddp '(2 4 6 1 3 5)) ==> 1

(remove-if #'oddp '(2 4 6 1 3 5)) ==> (2 4 6)

Miscellaneous

loop - All in one iteration construct. Read up on the simple cases of this if you don't know it already.

load - loads the indicated file, evaluating all Lisp forms in file. (load "foo.lisp") loads the file foo.lisp from the directory you were in when you entered Lisp.

compile-file - takes indicated file, and creates compiled xxxx.wfasl file, which may be loaded in place of lisp file for faster execution. See also compile for compiling an individual function.

dribble - makes a file that records an interactive session. (dribble "filename") starts it, (dribble) ends it

bye - Exits Lisp (Harlequin specific). Control-D also.

apropos - Searches for all currently defined Lisp symbols (function and variable names) containing given substring. Useful in conjunction with "describe" to find desired Lisp capability on-line.

(apropos 'concat) ==> all function names containing "concat", including "concatenate".

describe - On-line help for specified function name. For instance, once you discovered that "concatenate" is the function to concatenate strings, then
(describe 'concatenate)
would give brief information on using it.

Table of contents

Numeric Functions
List Functions
Predicates
Special Forms
Function Application
Miscellaneous