assoc -- r7rs Definition procedure;
Procedure variants:
((any null) -> (false))
((any assoc-list-not-null) -> (list-not-null-or-false))
any;assoc-list-not-null;list-not-null-or-false;((any null procedure-2) -> (false))
any;null;procedure-2;false;((any assoc-list-not-null procedure-2) -> (list-not-null-or-false))
any;assoc-list-not-null;procedure-2;list-not-null-or-false;scheme:base -- (scheme base);scheme -- (scheme);(assq obj alist) (assv obj alist) (assoc obj alist) (assoc obj alist compare)Domain: It is an error if
alist(for association list) is not a list of pairs.These procedures find the first pair in
alistwhose car field isobj, and returns that pair. If no pair inalisthasobjas its car, then#f(not the empty list) is returned. Theassqprocedure useseq?to compareobjwith the car fields of the pairs inalist, whileassvuseseqv?andassocusescompareif given andequal?otherwise.(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)) (assoc 2.0 '((1 1) (2 4) (3 9)) =) ===> (2 4) (assq 5 '((2 3) (5 7) (11 13))) ===> #unspecified (assv 5 '((2 3) (5 7) (11 13))) ===> (5 7)Rationale: Although they are often used as predicates,
memq,memv,member,assq,assv, andassocdo not have question marks in their names because they return potentially useful values rather than just#tor#f.
The text herein was sourced and adapted as described in the "R7RS attribution of various text snippets" appendix.