next up previous
Contents Next: not (PREDICATE) Up: Appendix: Selected LISP Previous: maxmin (FUNCTIONS)

member (FUNCTION)

Format: (member <item> <list> :test <test> :test-not <test-not> :key <key>)

Required arguments: 2

<item>: Any LISP expression <list>: A expression which returns a list

Keyword arguments: 3

<test>/<test-not>: A function or lambda expression that can be applied to compare <item> with elements of <list>. <key>: A function or lambda expression that can be applied to elements of <list>.

The elements of <list> are compared with the <item>. If <test> is not specified, eq is used; otherwise <test> is used. If <item> is found to match an element of <list>, a list containing all the elements from <item> to the end of <list> is returned. Otherwise NIL is returned. If <test-not> is specified, member returns a list beginning with the first UNmatched element of <list>. Specifying a <key> causes member to compare <item> with the result of applying <key> to each element of <list>, rather than to the element itself.

Examples:

>(member 'riker '(picard riker worf crusher))
(RIKER WORF CRUSHER)

>(member '(lieutenant worf) 
         '((captain picard)
           (commander riker)
           (lieutenant worf)
           (ensign crusher)))
NIL

>(member '(lieutenant worf) 
         '((captain picard)
           (commander riker)
           (lieutenant worf)
           (ensign crusher))
         :test #'equal)
((LIEUTENANT WORF) (ENSIGN CRUSHER))	 

>(member 'picard '(picard riker worf crusher) :test-not #'eq)
(RIKER WORF CRUSHER)

>(member 'worf 
         '((captain picard)
           (commander riker)
           (lieutenant worf)
           (ensign crusher))
         :key #'second)
((LIEUTENANT WORF) (ENSIGN CRUSHER))



© Colin Allen & Maneesh Dhagat
November 1999