Association Lists

An association list or alist is a list of pairs, in which the first element ( car) of each pair is a key value and the remainder of it is associated data. Association lists are a simple way to implement small databases.

(assoc x alist) searches alist, a list of pairs, for a pair whose car equals x. The result is the pair that was found, or #f if no matching pair is found.


(assoc 'two '((one 1) (two 2) (three 3)))
            =  (two 2)
An additional operation (in this case, cadr) on the result of assoc is used to get the desired data.

(cadr (assoc 'two '((one 1) (two 2) ...)))
             =  2

Three assoc functions use different equality predicates:

Contents    Page-10    Prev    Next    Page+10    Index