emacs.d/clones/lisp/colinallen.dnsalias.org/lp/node103.html

100 lines
3.3 KiB
HTML
Raw Normal View History

2022-08-02 12:34:59 +02:00
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Originally converted to HTML using LaTeX2HTML 95 (Thu Jan 19 1995) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE> member (FUNCTION)</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" member (FUNCTION)">
<meta name="keywords" value="lp">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<BR> <HR>
<A HREF="node104.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A>
<A HREF="node72.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A>
<A HREF="node102.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <BR>
<A HREF="lp.html"><B>Contents</B></A>
<B> Next:</B>
<A HREF="node104.html"> not (PREDICATE)</A>
<B>Up:</B>
<A HREF="node72.html"> Appendix: Selected Lisp </A>
<B> Previous:</B>
<A HREF="node102.html"> maxmin (FUNCTIONS)</A>
<BR> <HR> <P>
<H1> member (FUNCTION)</H1>
<P>
<b> Format:</b>
<tt> (member &lt;item&gt; &lt;list&gt; </tt>
<tt> :test &lt;test&gt; </tt>
<tt> :test-not &lt;test-not&gt; </tt>
<tt> :key &lt;key&gt; )</tt>
<P>
<b> Required arguments:</b>
2
<P>
<tt> &lt;item&gt; </tt>: Any Lisp expression
<tt> &lt;list&gt; </tt>: A expression which returns a list
<P>
<b> Keyword arguments:</b>
3
<P>
<tt> &lt;test&gt; /&lt;test-not&gt; </tt>: A function or lambda expression that
can be applied to compare <tt> &lt;item&gt; </tt> with elements of <tt> &lt;list&gt; </tt>.
<tt> &lt;key&gt; </tt>: A function or lambda expression that can be applied
to elements of <tt> &lt;list&gt; </tt>.
<P>
The elements of <tt> &lt;list&gt; </tt> are compared with the <tt> &lt;item&gt; </tt>. If
<tt> &lt;test&gt; </tt> is not specified, eq is used; otherwise <tt> &lt;test&gt; </tt> is used.
If <tt> &lt;item&gt; </tt> is found to match an element of <tt> &lt;list&gt; </tt>, a list containing
all the elements from <tt> &lt;item&gt; </tt> to the end of <tt> &lt;list&gt; </tt> is returned.
Otherwise NIL is returned. If <tt> &lt;test-not&gt; </tt> is specified, member
returns a list beginning with the first UNmatched element of <tt> &lt;list&gt; </tt>.
Specifying a <tt> &lt;key&gt; </tt> causes member to compare <tt> &lt;item&gt; </tt> with the
result of applying <tt> &lt;key&gt; </tt> to each element of <tt> &lt;list&gt; </tt>, rather than
to the element itself.
<P>
<b> Examples:</b>
<P>
<BLOCKQUOTE>
<PRE>&gt; (member 'riker '(picard riker worf crusher))
(RIKER WORF CRUSHER)
&gt; (member '(lieutenant worf)
'((captain picard)
(commander riker)
(lieutenant worf)
(ensign crusher)))
NIL
</PRE>
</BLOCKQUOTE>
<P>
<BLOCKQUOTE>
<PRE>&gt; (member '(lieutenant worf)
'((captain picard)
(commander riker)
(lieutenant worf)
(ensign crusher))
:test #'equal)
((LIEUTENANT WORF) (ENSIGN CRUSHER))
&gt; (member 'picard '(picard riker worf crusher) :test-not #'eq)
(RIKER WORF CRUSHER)
&gt; (member 'worf
'((captain picard)
(commander riker)
(lieutenant worf)
(ensign crusher))
:key #'second)
((LIEUTENANT WORF) (ENSIGN CRUSHER))
</PRE>
</BLOCKQUOTE>
<P>
<BR> <HR>
<P>
<ADDRESS>
<I>&#169; Colin Allen &amp; Maneesh Dhagat <BR>
March 2007 </I>
</ADDRESS>
</BODY>