User Tools


Function RASSOC, RASSOC-IF, RASSOC-IF-NOT

Syntax

  • rassoc item alist &key key test test-not → entry
  • rassoc-if predicate alist &key key → entry
  • rassoc-if-not predicate alist &key key → entry

Arguments and Values

Description

rassoc, rassoc-if, and rassoc-if-not return the first cons whose cdr satisfies the test. If no such cons is found, nil is returned.

If nil appears in alist in place of a pair, it is ignored.

Examples

(defparameter *alist* '((1 . "one") (2 . "two") (3 . 3)))

*ALIST*

(rassoc 3 *alist*)

(3 . 3)

(rassoc "two" *alist*)

NIL

(rassoc "two" *alist* :test #'equal)

(2 . "two")

(rassoc 1 *alist* :key #'(lambda (x) (if (numberp x) (/ x 3))))

(3 . 3)

(rassoc 'a '((a . b) (b . c) (c . a) (z . a)))

(C . A)

(rassoc-if #'stringp *alist*)

(1 . "one")

(rassoc-if-not #'vectorp *alist*)

(3 . 3)

Side Effects

None.

Affected By

None.

Exceptional Situations

None.

See Also

Function ASSOC, {\secref\TraversalRules}

Example Implementation

The expressions

(rassoc item list :test fn)

and

(find item list :test fn :key #'cdr)

are equivalent in meaning, except when the item is nil and nil appears in place of a pair in the alist. See the function assoc.

Notes

The :test-not parameter is deprecated.

The function rassoc-if-not is deprecated.

It is possible to rplaca the result of rassoc, provided that it is not nil, in order to "update" alist.

\issue{ASSOC-RASSOC-IF-KEY} \issue{TEST-NOT-IF-NOT:FLUSH-ALL} \issue{ASSOC-RASSOC-IF-KEY:YES} \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE}