[LISPWORKS][Common Lisp HyperSpec (TM)] [Previous][Up][Next]



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:

item---an object.

list---a proper list.

predicate---a designator for a function of one argument that returns a generalized boolean.

test---a designator for a function of two arguments that returns a generalized boolean.

test-not---a designator for a function of two arguments that returns a generalized boolean.

key---a designator for a function of one argument, or nil.

tail---a list.


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.


 (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:

find, position, Section 3.6 (Traversal Rules and Side Effects)


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

The following X3J13 cleanup issues, not part of the specification, apply to this section:

[Starting Points][Contents][Index][Symbols][Glossary][Issues]
Copyright 1996-2005, LispWorks Ltd. All rights reserved.