chickadee » scheme » assoc

assq obj alistprocedure
assv obj alistprocedure
assoc obj alistprocedure

Alist (for "association list") must be a list of pairs. These procedures find the first pair in alist whose car field is obj, and returns that pair. If no pair in alist has obj as its car, then #f (not the empty list) is returned. Assq uses eq? to compare obj with the car fields of the pairs in alist, while assv uses eqv? and assoc uses equal?.

(define e '((a 1) (b 2) (c 3)))
(assq 'a e)             ===>  (a 1)
(assq 'b e)             ===>  (b 2)
(assq 'd e)             ===>  #f
(assq (list 'a) '(((a)) ((b)) ((c))))
                        ===>  #f
(assoc (list 'a) '(((a)) ((b)) ((c))))   
                                   ===>  ((a))
(assq 5 '((2 3) (5 7) (11 13)))    
                                   ===>  unspecified
(assv 5 '((2 3) (5 7) (11 13)))    
                                   ===>  (5 7)

Rationale: Although they are ordinarily used as predicates, memq, memv, member, assq, assv, and assoc do not have question marks in their names because they return useful values rather than just #t or #f.