Look up value in association list
(rassoc x alist)
(rassoc x alist :test 'eql) ; same as above (eql as equality test)
(rassoc x alist :test 'eq) ; same, but eq is equality test
(rassoc x alist :test 'equal) ; same, but equal is equality test
(Rassoc x alist) is the first member of alist whose cdr
is x, or nil if no such member exists. (rassoc x alist) is
thus similar to (assoc x alist), the difference being that it looks for
the first pair in the given alist whose cdr, rather than car,
is eql to x. See assoc. The optional keyword,
:TEST, has no effect logically, but provides the test (default eql) used for comparing x with the cdrs of successive elements
The guard for a call of rassoc depends on the test. In all
cases, the second argument must satisfy alistp. If the test is eql, then either the first argument must be suitable for eql (see
eqlablep) or the second argument must satisfy r-eqlable-alistp.
If the test is eq, then either the first argument must be a symbol or
the second argument must satisfy r-symbol-alistp.
See equality-variants for a discussion of the relation between
rassoc and its variants:
(rassoc-eq x lst) is equivalent to (rassoc x lst :test
(rassoc-equal x lst) is equivalent to (rassoc x lst :test
In particular, reasoning about any of these primitives reduces to reasoning
about the function rassoc-equal.
(defun rassoc-equal (x alist)
(declare (xargs :guard (alistp alist)))
(cond ((endp alist) nil)
((equal x (cdr (car alist)))
(t (rassoc-equal x (cdr alist)))))
Rassoc is defined by Common Lisp. See any Common Lisp documentation
for more information.