REDUCE

5.4 Functions for Building and Searching A-Lists

(assoc U:any V:a-list): pair, nil expr
If U occurs as the car portion of an element of the a-list V, the pair in which U occurred is returned, otherwise nil is returned. The function equal is used to test for equality. As illustrated below, it is possible to update the table that was the second argument to assoc by using the function rplacd on the result.
    (de assoc (u v)  
      (cond ((not (pairp v)) nil)  
            ((and (pairp (car v)) (equal u (caar v))) (car v))  
            (t (assoc u (cdr v)))))  
 
    1 lisp> (setq table '((oranges . 4) (apples . 2)))  
    ((oranges . 4) (apples . 2))  
 
    2 lisp> (rplacd (assoc 'apples table) 0)  
    (apples . 0)  
 
    3 lisp> table  
    ((oranges . 4) (apples . 0))

(atsoc R1:any R2:any): any expr
Similar to assoc except that eq is used to make comparisons.

(ass F:function U:any V:a-list): pair, nil expr
Ass is a generalized assoc function. F is the comparison function.

(sassoc U:any V:a-list FN:function): any expr
Searches the a-list V for an occurrence of U. If U is not in the a-list, the evaluation of function FN is returned. Note that FN should be a function with no formal parameters.
    (de sassoc (u v fn)  
      (cond ((not (pairp v)) (apply fn nil))  
            ((and (pairp (car v)) (equal u (caar v))) (car v))  
            (t (sassoc u (cdr v) fn))))

(pair U:list V:list): a-list expr
U and V are lists which must have an identical number of elements. If not, an error occurs. Returned is a list in which each element is a pair, the car of the pair being from U and the cdr being the corresponding element from V.
    (de pair (u v)  
      (cond ((and (pairp u) (pairp v))  
             (cons (cons (car u) (car v)) (pair (cdr u) (cdr v))))  
            ((or (pairp u) (pairp v))  
             (length-error))  
            (t nil)))