1
0
Fork 0
cl-sites/novaspec.org/cl/f_set-exclusive-or.html
2025-02-05 18:52:26 +01:00

506 lines
No EOL
10 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>set-exclusive-or, nset-exclusive-or | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_set-exclusive-or.html"
><LINK REL="next" HREF="f_subsetp.html" TYPE="text/html" TITLE="subsetp"
><LINK REL="prev" HREF="f_set-difference.html" TYPE="text/html" TITLE="set-difference, nset-difference"
><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_set-exclusive-or.html"
>set-exclusive-or, nset-exclusive-or</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_set-difference.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_subsetp.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="set-exclusive-or, nset-exclusive-or"
></SPAN
><B
>set-exclusive-or, nset-exclusive-or</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
>set-exclusive-or</B
> <SPAN CLASS="cmssi"
>list-1</SPAN
> <SPAN CLASS="cmssi"
>list-2</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"
>result-list</SPAN
></P
><P CLASS="j"
><B
>nset-exclusive-or</B
> <SPAN CLASS="cmssi"
>list-1</SPAN
> <SPAN CLASS="cmssi"
>list-2</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"
>result-list</SPAN
></P
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>list-1</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"
>list-2</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"
>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"
>result-list</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_set-exclusive-or.html" CLASS="funref"
><B
>set-exclusive-or</B
></A
> returns a <A HREF="26_1_Glossary.html#list"
><EM CLASS="term"
>list</EM
></A
> of elements that appear in exactly one of <VAR CLASS="param"
>list-1</VAR
> and <VAR CLASS="param"
>list-2</VAR
>. </P
><P CLASS="j"
><A HREF="f_set-exclusive-or.html" CLASS="funref"
><B
>nset-exclusive-or</B
></A
> is the <A HREF="26_1_Glossary.html#destructive"
><EM CLASS="term"
>destructive</EM
></A
> version of <A HREF="f_set-exclusive-or.html" CLASS="funref"
><B
>set-exclusive-or</B
></A
>. </P
><P CLASS="j"
>For all possible ordered pairs consisting of one element from <VAR CLASS="param"
>list-1</VAR
> and one element from <VAR CLASS="param"
>list-2</VAR
>, the <SPAN CLASS="kwd"
><SPAN CLASS="cmtt"
>:test</SPAN
></SPAN
> or <SPAN CLASS="kwd"
><SPAN CLASS="cmtt"
>:test-not</SPAN
></SPAN
> function is used to determine whether they <A HREF="26_1_Glossary.html#satisfy_the_test"
><EM CLASS="term"
>satisfy the test</EM
></A
>. </P
><P CLASS="j"
>If <SPAN CLASS="kwd"
><SPAN CLASS="cmtt"
>:key</SPAN
></SPAN
> is supplied, it is used to extract the part to be tested from the <VAR CLASS="param"
>list-1</VAR
> or <VAR CLASS="param"
>list-2</VAR
> element. The first argument to the <SPAN CLASS="kwd"
><SPAN CLASS="cmtt"
>:test</SPAN
></SPAN
> or <SPAN CLASS="kwd"
><SPAN CLASS="cmtt"
>:test-not</SPAN
></SPAN
> function is the part of an element of <VAR CLASS="param"
>list-1</VAR
> extracted by the <SPAN CLASS="kwd"
><SPAN CLASS="cmtt"
>:key</SPAN
></SPAN
> function (if supplied); the second argument is the part of an element of <VAR CLASS="param"
>list-2</VAR
> extracted by the <SPAN CLASS="kwd"
><SPAN CLASS="cmtt"
>:key</SPAN
></SPAN
> function (if supplied). If <SPAN CLASS="kwd"
><SPAN CLASS="cmtt"
>:key</SPAN
></SPAN
> is not supplied or <SPAN CLASS="misc"
><B
>nil</B
></SPAN
>, the <VAR CLASS="param"
>list-1</VAR
> or <VAR CLASS="param"
>list-2</VAR
> element is used. </P
><P CLASS="j"
>The result contains precisely those elements of <VAR CLASS="param"
>list-1</VAR
> and <VAR CLASS="param"
>list-2</VAR
> that appear in no matching pair. </P
><P CLASS="j"
>The result <A HREF="26_1_Glossary.html#list"
><EM CLASS="term"
>list</EM
></A
> of <A HREF="f_set-exclusive-or.html" CLASS="funref"
><B
>set-exclusive-or</B
></A
> might share storage with one of <VAR CLASS="param"
>list-1</VAR
> or <VAR CLASS="param"
>list-2</VAR
>.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
> (setq lst1 (list 1 "a" "b")
lst2 (list 1 "A" "b")) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (1 "A" "b")
(set-exclusive-or lst1 lst2) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> ("b" "A" "b" "a")
(set-exclusive-or lst1 lst2 :test #'equal) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> ("A" "a")
(set-exclusive-or lst1 lst2 :test 'equalp) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL
(nset-exclusive-or lst1 lst2) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> ("a" "b" "A" "b")
(setq lst1 (list (("a" . "b") ("c" . "d") ("e" . "f"))))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (("a" . "b") ("c" . "d") ("e" . "f"))
(setq lst2 (list (("c" . "a") ("e" . "b") ("d" . "a"))))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (("c" . "a") ("e" . "b") ("d" . "a"))
(nset-exclusive-or lst1 lst2 :test #'string= :key #'cdr)
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (("c" . "d") ("e" . "f") ("c" . "a") ("d" . "a"))
lst1 <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (("a" . "b") ("c" . "d") ("e" . "f"))
lst2 <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (("c" . "a") ("d" . "a"))</PRE
></DD
><DT
><B
>Side Effects</B
></DT
><DD
><P CLASS="j"
><A HREF="f_set-exclusive-or.html" CLASS="funref"
><B
>nset-exclusive-or</B
></A
> is permitted to modify any part, <A HREF="26_1_Glossary.html#car"
><EM CLASS="term"
>car</EM
></A
> or <A HREF="26_1_Glossary.html#cdr"
><EM CLASS="term"
>cdr</EM
></A
>, of the <A HREF="26_1_Glossary.html#list_structure"
><EM CLASS="term"
>list structure</EM
></A
> of <VAR CLASS="param"
>list-1</VAR
> or <VAR CLASS="param"
>list-2</VAR
>.</P
></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-1</VAR
> and <VAR CLASS="param"
>list-2</VAR
> are not <A HREF="26_1_Glossary.html#proper_list"
><EM CLASS="term"
>proper lists</EM
></A
>.</P
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="3_2_Compilation.html#sec_3_2_1" CLASS="secref"
><SPAN CLASS="cmr"
>Section</SPAN
> <SPAN CLASS="cmr"
>3.2.1</SPAN
> <SPAN CLASS="cmr"
>(Compiler</SPAN
> <SPAN CLASS="cmr"
>Terminology)</SPAN
></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"
>Since the <A HREF="f_set-exclusive-or.html" CLASS="funref"
><B
>nset-exclusive-or</B
></A
> side effect is not required, it should not be used in for-effect-only positions in portable code.</P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_set-difference.html" CLASS="prev"
>&#8592;</A
><A HREF="f_subsetp.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
>