CLCS
Function

member, member-if, member-if-not

member item list &key key test test-not ⇒ tail

member-if predicate list &key key ⇒ tail

member-if-not predicate list &key key ⇒ tail

Arguments and Values

iteman object.
lista proper list.
predicatea designator for a function of one argument that returns a generalized boolean.
testa designator for a function of two arguments that returns a generalized boolean.
test-nota designator for a function of two arguments that returns a generalized boolean.
keya designator for a function of one argument, or nil.
taila list.

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)

Exceptional Situations

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

See Also

find; find-if; find-if-not, ‘position; position-if; position-if-not’,

Traversal Rules and Side Effects

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).