User Tools


Function MEMBER, MEMBER-IF, MEMBER-IF-NOT

Syntax

  • member item list &key key test test-nottail
  • member-if predicate list &key keytail
  • member-if-not predicate list &key keytail

Arguments and Values

Description

member, member-if, and member-if-not each search list for item or for a top-level element that satisfies the test. The argument to the predicate function is an element of list.

If some element satisfies the test, the tail of list beginning with this element is returned; otherwise nil is returned.

list is searched on the top level only.

Examples

(member 2 '(1 2 3))

(2 3)

(member 2 '((1 . 2) (3 . 4)) :test-not #'= :key #'cdr)

((3 . 4))

(member 'e '(a b c d))

NIL

(member-if #'listp '(a b nil c d))

(NIL C D)

(member-if #'numberp '(a #\Space 5/3 foo))

(5/3 FOO)

(member-if-not #'zerop '(3 6 9 11 . 12) :key #'(lambda (x) (mod x 3)))

(11 . 12)

Side Effects

None.

Affected By

None.

Exceptional Situations

Should be prepared to signal an error of type type-error if list is not a proper list.

See Also

Function FIND, Function POSITION, {\secref\TraversalRules}

Example Implementation

To be done.

Notes

The :test-not parameter is deprecated.

The function member-if-not is deprecated.

In the following

(member 'a '(g (a y) c a d e a f))

(A D E A F)

the value returned by member is identical to the portion of the list beginning with a. Thus rplaca on the result of member can be used to alter the part of the list where a was found (assuming a check has been made that member did not return nil).

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