chickadee » srfi-1 » assoc

assoc key alist #!optional =procedure

assoc is extended from its R5RS definition to allow the client to pass in an optional equality procedure = used to compare keys.

The comparison procedure is used to compare the elements E_I of LIST to the KEY parameter in this way:

(= KEY (car E_I)) ; list is (E1 ... En)

That is, the first argument is always KEY, and the second argument is one of the list elements. Thus one can reliably find the first entry of ALIST whose key is greater than five with (assoc 5 ALIST <)

Note that fully general alist searching may be performed with the find-tail and find procedures, e.g.

;; Look up the first association in ALIST with an even key:
(find (lambda (a) (even? (car a))) alist)