1
0
Fork 0
cl-sites/novaspec.org/cl/f_member.html

465 lines
9 KiB
HTML
Raw Normal View History

2025-02-05 18:52:26 +01:00
<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>member, member-if, member-if-not | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_member.html"
><LINK REL="next" HREF="f_mapc.html" TYPE="text/html" TITLE="mapc, mapcar, mapcan, mapl, maplist, mapcon"
><LINK REL="prev" HREF="f_rest.html" TYPE="text/html" TITLE="rest"
><LINK REL="up" HREF="14_2_Conses_Dictionary.html" TYPE="text/html" TITLE="14.2 Conses Dictionary"
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
><SCRIPT SRC="dpans.js%3F3909942064"
></SCRIPT
><SCRIPT SRC="apropos.js%3F3909942064"
></SCRIPT
></HEAD
><BODY
><DIV
><DIV CLASS="topnav"
><DIV CLASS="breadcrumb"
><SPAN CLASS="breadcrumb-item"
><A HREF="index.html"
>Common Lisp Nova Spec</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="14_Conses.html"
>14. Conses</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="14_2_Conses_Dictionary.html"
>14.2 Conses Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_member.html"
>member, member-if, member-if-not</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_rest.html" CLASS="prev"
>&#8592;</A
><SPAN ID="apropos-label"
>Apropos </SPAN
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
><A HREF="f_mapc.html" CLASS="next"
>&#8594;</A
></DIV
><DIV ID="apropos-res"
></DIV
></DIV
></DIV
><DIV CLASS="matter"
><DIV CLASS="com"
><DIV CLASS="begincom"
><HR
><TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0"
><TR
><TD ALIGN="LEFT" VALIGN="BASELINE" WIDTH="100%" CLASS="name"
><SPAN CLASS="idx" DATA-KIND="idxref" DATA-TERM="member, member-if, member-if-not"
></SPAN
><B
>member, member-if, member-if-not</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Function</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><P CLASS="j"
><B
>member</B
> <SPAN CLASS="cmssi"
>item</SPAN
> <SPAN CLASS="cmssi"
>list</SPAN
> <SPAN CLASS="cmtt"
>&amp;key</SPAN
> <SPAN CLASS="cmssi"
>key</SPAN
> <SPAN CLASS="cmssi"
>test</SPAN
> <SPAN CLASS="cmssi"
>test-not</SPAN
> <SPAN CLASS="arrow"
>&#8594;</SPAN
> <SPAN CLASS="cmssi"
>tail</SPAN
></P
><P CLASS="j"
><B
>member-if</B
> <SPAN CLASS="cmssi"
>predicate</SPAN
> <SPAN CLASS="cmssi"
>list</SPAN
> <SPAN CLASS="cmtt"
>&amp;key</SPAN
> <SPAN CLASS="cmssi"
>key</SPAN
> <SPAN CLASS="arrow"
>&#8594;</SPAN
> <SPAN CLASS="cmssi"
>tail</SPAN
></P
><P CLASS="j"
><B
>member-if-not</B
> <SPAN CLASS="cmssi"
>predicate</SPAN
> <SPAN CLASS="cmssi"
>list</SPAN
> <SPAN CLASS="cmtt"
>&amp;key</SPAN
> <SPAN CLASS="cmssi"
>key</SPAN
> <SPAN CLASS="arrow"
>&#8594;</SPAN
> <SPAN CLASS="cmssi"
>tail</SPAN
></P
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>item</VAR
> &#8212; an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>list</VAR
> &#8212; a <A HREF="26_1_Glossary.html#proper_list"
><EM CLASS="term"
>proper list</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>predicate</VAR
> &#8212; a <A HREF="26_1_Glossary.html#designator"
><EM CLASS="term"
>designator</EM
></A
> for a <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> of one <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>argument</EM
></A
> that returns a <A HREF="26_1_Glossary.html#generalized_boolean"
><EM CLASS="term"
>generalized boolean</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>test</VAR
> &#8212; a <A HREF="26_1_Glossary.html#designator"
><EM CLASS="term"
>designator</EM
></A
> for a <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> of two <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>arguments</EM
></A
> that returns a <A HREF="26_1_Glossary.html#generalized_boolean"
><EM CLASS="term"
>generalized boolean</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>test-not</VAR
> &#8212; a <A HREF="26_1_Glossary.html#designator"
><EM CLASS="term"
>designator</EM
></A
> for a <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> of two <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>arguments</EM
></A
> that returns a <A HREF="26_1_Glossary.html#generalized_boolean"
><EM CLASS="term"
>generalized boolean</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>key</VAR
> &#8212; a <A HREF="26_1_Glossary.html#designator"
><EM CLASS="term"
>designator</EM
></A
> for a <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> of one argument, or <SPAN CLASS="misc"
><B
>nil</B
></SPAN
>. </P
><P CLASS="j"
><VAR CLASS="param"
>tail</VAR
> &#8212; a <A HREF="26_1_Glossary.html#list"
><EM CLASS="term"
>list</EM
></A
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
><A HREF="f_member.html" CLASS="funref"
><B
>member</B
></A
>, <A HREF="f_member.html" CLASS="funref"
><B
>member-if</B
></A
>, and <A HREF="f_member.html" CLASS="funref"
><B
>member-if-not</B
></A
> each search <VAR CLASS="param"
>list</VAR
> for <VAR CLASS="param"
>item</VAR
> or for a top-level element that <EM CLASS="term"
>satisfies the test</EM
>. The argument to the <VAR CLASS="param"
>predicate</VAR
> function is an element of <VAR CLASS="param"
>list</VAR
>. </P
><P CLASS="j"
>If some element <EM CLASS="term"
>satisfies the test</EM
>, the tail of <VAR CLASS="param"
>list</VAR
> beginning with this element is returned; otherwise <SPAN CLASS="misc"
><B
>nil</B
></SPAN
> is returned. </P
><P CLASS="j"
><VAR CLASS="param"
>list</VAR
> is searched on the top level only.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
>(member 2 '(1 2 3)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (2 3)
(member 2 '((1 . 2) (3 . 4)) :test-not #'= :key #'cdr) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> ((3 . 4))
(member 'e '(a b c d)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL</PRE
><PRE CLASS="screen"
>(member-if #'listp '(a b nil c d)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (NIL C D)
(member-if #'numberp '(a #\Space 5/3 foo)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (5/3 FOO)
(member-if-not #'zerop
'(3 6 9 11 . 12)
:key #'(lambda (x) (mod x 3))) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (11 . 12)</PRE
></DD
><DT
><B
>Exceptional Situations</B
></DT
><DD
><P CLASS="j"
>Should be prepared to signal an error of <A HREF="26_1_Glossary.html#type"
><EM CLASS="term"
>type</EM
></A
> <A HREF="t_type-error.html" CLASS="typeref"
><B
>type-error</B
></A
> if <VAR CLASS="param"
>list</VAR
> is not a <A HREF="26_1_Glossary.html#proper_list"
><EM CLASS="term"
>proper list</EM
></A
>.</P
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_find.html" CLASS="funref"
><B
>find</B
></A
>, <A HREF="f_position.html" CLASS="funref"
><B
>position</B
></A
>, <A HREF="3_6_Traversal_Rules_and_Side_Effects.html#sec_3_6" CLASS="secref"
><SPAN CLASS="cmr"
>Section</SPAN
> <SPAN CLASS="cmr"
>3.6</SPAN
> <SPAN CLASS="cmr"
>(Traversal</SPAN
> <SPAN CLASS="cmr"
>Rules</SPAN
> <SPAN CLASS="cmr"
>and</SPAN
> <SPAN CLASS="cmr"
>Side</SPAN
> <SPAN CLASS="cmr"
>Effects)</SPAN
></A
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><P CLASS="j"
>The <SPAN CLASS="kwd"
><SPAN CLASS="cmtt"
>:test-not</SPAN
></SPAN
> parameter is deprecated. </P
><P CLASS="j"
>The <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> <A HREF="f_member.html" CLASS="funref"
><B
>member-if-not</B
></A
> is deprecated. </P
><P CLASS="j"
>In the following</P
><PRE CLASS="screen"
>(member 'a '(g (a y) c a d e a f)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (A D E A F)</PRE
><P CLASS="j"
>the value returned by <A HREF="f_member.html" CLASS="funref"
><B
>member</B
></A
> is <A HREF="26_1_Glossary.html#identical"
><EM CLASS="term"
>identical</EM
></A
> to the portion of the <A HREF="26_1_Glossary.html#list"
><EM CLASS="term"
>list</EM
></A
> beginning with <CODE CLASS="f"
>a</CODE
>. Thus <A HREF="f_rplaca.html" CLASS="funref"
><B
>rplaca</B
></A
> on the result of <A HREF="f_member.html" CLASS="funref"
><B
>member</B
></A
> can be used to alter the part of the <A HREF="26_1_Glossary.html#list"
><EM CLASS="term"
>list</EM
></A
> where <CODE CLASS="f"
>a</CODE
> was found (assuming a check has been made that <A HREF="f_member.html" CLASS="funref"
><B
>member</B
></A
> did not return <SPAN CLASS="misc"
><B
>nil</B
></SPAN
>).</P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_rest.html" CLASS="prev"
>&#8592;</A
><A HREF="f_mapc.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>