;;; Procedure: ;;; assoc ;;; Parameters: ;;; key, a Scheme value ;;; alist, an association list ;;; Purpose: ;;; Find an entry with key key in alist. ;;; Produces: ;;; entry, a Scheme value ;;; Preconditions: ;;; No additional ;;; Postconditions: ;;; If there is an index, i, such that ;;; (equal? key (car (list-ref alist i))) ;;; then entry is the first such entry ;;; Otherwise, entry is false (#f) (define assoc (lambda (key alist) (cond ; If there are no entries left in the association list, ; there are no entries with the given key. ((null? alist) #f) ; If the key we're looking for is the key of the first ; entry, then use that entry. ((equal? key (car (car alist))) (car alist)) ; Otherwise, look in the rest of the association list. (else (assoc key (cdr alist))))))