Association Lists

A simple ``database'' facility is provided by the association list. This is a list of sublists, in which the first element of a sublist is the key value and the remainder of the sublist is the associated data. Association lists are a simple way to implement small databases.

(ASSOC x l) searches l, a list of lists, for an element that begins with x. The result is the element that was found, or NIL if no matching element is found.


(ASSOC 'TWO '((ONE 1) (TWO 2) (THREE 3)))

                 =  (TWO 2)
Note that an additional operation (in this case, CADR) is usually required on the result of ASSOC to get the desired data.

(CADR (ASSOC 'TWO '((ONE 1) (TWO 2) ...)))

                 =  2

Contents    Page-10    Prev    Next    Page+10    Index