592 lines
No EOL
12 KiB
HTML
592 lines
No EOL
12 KiB
HTML
<!DOCTYPE HTML>
|
|
<HTML LANG="en-us"
|
|
><HEAD
|
|
><TITLE
|
|
>intersection, nintersection | Common Lisp Nova Spec</TITLE
|
|
><META CHARSET="US-ASCII"
|
|
><LINK REL="canonical" HREF="f_intersection.html"
|
|
><LINK REL="next" HREF="f_adjoin.html" TYPE="text/html" TITLE="adjoin"
|
|
><LINK REL="prev" HREF="f_remf.html" TYPE="text/html" TITLE="remf"
|
|
><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"
|
|
>→ <A HREF="14_Conses.html"
|
|
>14. Conses</A
|
|
></SPAN
|
|
> <SPAN CLASS="breadcrumb-item"
|
|
>→ <A HREF="14_2_Conses_Dictionary.html"
|
|
>14.2 Conses Dictionary</A
|
|
></SPAN
|
|
> <SPAN CLASS="breadcrumb-item"
|
|
>→ <A HREF="f_intersection.html"
|
|
>intersection, nintersection</A
|
|
></SPAN
|
|
></DIV
|
|
><DIV CLASS="apropos"
|
|
><DIV CLASS="apropos-io"
|
|
><A HREF="f_remf.html" CLASS="prev"
|
|
>←</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_adjoin.html" CLASS="next"
|
|
>→</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="intersection, nintersection"
|
|
></SPAN
|
|
><B
|
|
>intersection, nintersection</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
|
|
>intersection</B
|
|
> <SPAN CLASS="cmssi"
|
|
>list-1</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>list-2</SPAN
|
|
> <SPAN CLASS="cmtt"
|
|
>&key</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>key</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>test</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>test-not</SPAN
|
|
> <SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>result-list</SPAN
|
|
></P
|
|
><P CLASS="j"
|
|
><B
|
|
>nintersection</B
|
|
> <SPAN CLASS="cmssi"
|
|
>list-1</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>list-2</SPAN
|
|
> <SPAN CLASS="cmtt"
|
|
>&key</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>key</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>test</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>test-not</SPAN
|
|
> <SPAN CLASS="arrow"
|
|
>→</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
|
|
> — 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
|
|
> — 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
|
|
> — 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
|
|
> — 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
|
|
> — 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
|
|
> — 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_intersection.html" CLASS="funref"
|
|
><B
|
|
>intersection</B
|
|
></A
|
|
> and <A HREF="f_intersection.html" CLASS="funref"
|
|
><B
|
|
>nintersection</B
|
|
></A
|
|
> return a <A HREF="26_1_Glossary.html#list"
|
|
><EM CLASS="term"
|
|
>list</EM
|
|
></A
|
|
> that contains every element that occurs in both <VAR CLASS="param"
|
|
>list-1</VAR
|
|
> and <VAR CLASS="param"
|
|
>list-2</VAR
|
|
>. </P
|
|
><P CLASS="j"
|
|
><A HREF="f_intersection.html" CLASS="funref"
|
|
><B
|
|
>nintersection</B
|
|
></A
|
|
> is the destructive version of <A HREF="f_intersection.html" CLASS="funref"
|
|
><B
|
|
>intersection</B
|
|
></A
|
|
>. It performs the same operation, but may destroy <VAR CLASS="param"
|
|
>list-1</VAR
|
|
> using its cells to construct the result. <VAR CLASS="param"
|
|
>list-2</VAR
|
|
> is not destroyed. </P
|
|
><P CLASS="j"
|
|
>The intersection operation is described as follows. For all possible ordered pairs consisting of one <A HREF="26_1_Glossary.html#element"
|
|
><EM CLASS="term"
|
|
>element</EM
|
|
></A
|
|
> from <VAR CLASS="param"
|
|
>list-1</VAR
|
|
> and one <A HREF="26_1_Glossary.html#element"
|
|
><EM CLASS="term"
|
|
>element</EM
|
|
></A
|
|
> from <VAR CLASS="param"
|
|
>list-2</VAR
|
|
>, <SPAN CLASS="kwd"
|
|
><SPAN CLASS="cmtt"
|
|
>:test</SPAN
|
|
></SPAN
|
|
> or <SPAN CLASS="kwd"
|
|
><SPAN CLASS="cmtt"
|
|
>:test-not</SPAN
|
|
></SPAN
|
|
> are used to determine whether they <A HREF="26_1_Glossary.html#satisfy_the_test"
|
|
><EM CLASS="term"
|
|
>satisfy the test</EM
|
|
></A
|
|
>. 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 an element of <VAR CLASS="param"
|
|
>list-1</VAR
|
|
>; the second argument is an element of <VAR CLASS="param"
|
|
>list-2</VAR
|
|
>. If <SPAN CLASS="kwd"
|
|
><SPAN CLASS="cmtt"
|
|
>:test</SPAN
|
|
></SPAN
|
|
> or <SPAN CLASS="kwd"
|
|
><SPAN CLASS="cmtt"
|
|
>:test-not</SPAN
|
|
></SPAN
|
|
> is not supplied, <A HREF="f_eql.html" CLASS="funref"
|
|
><B
|
|
>eql</B
|
|
></A
|
|
> is used. It is an error if <SPAN CLASS="kwd"
|
|
><SPAN CLASS="cmtt"
|
|
>:test</SPAN
|
|
></SPAN
|
|
> and <SPAN CLASS="kwd"
|
|
><SPAN CLASS="cmtt"
|
|
>:test-not</SPAN
|
|
></SPAN
|
|
> are supplied in the same function call. </P
|
|
><P CLASS="j"
|
|
>If <SPAN CLASS="kwd"
|
|
><SPAN CLASS="cmtt"
|
|
>:key</SPAN
|
|
></SPAN
|
|
> is supplied (and not <SPAN CLASS="misc"
|
|
><B
|
|
>nil</B
|
|
></SPAN
|
|
>), it is used to extract the part to be tested from the <VAR CLASS="param"
|
|
>list</VAR
|
|
> element. The argument to the <SPAN CLASS="kwd"
|
|
><SPAN CLASS="cmtt"
|
|
>:key</SPAN
|
|
></SPAN
|
|
> function is an element of either <VAR CLASS="param"
|
|
>list-1</VAR
|
|
> or <VAR CLASS="param"
|
|
>list-2</VAR
|
|
>; the <SPAN CLASS="kwd"
|
|
><SPAN CLASS="cmtt"
|
|
>:key</SPAN
|
|
></SPAN
|
|
> function typically returns part of the supplied element. 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
|
|
> and <VAR CLASS="param"
|
|
>list-2</VAR
|
|
> elements are used. </P
|
|
><P CLASS="j"
|
|
>For every pair that <EM CLASS="term"
|
|
>satifies the test</EM
|
|
>, exactly one of the two elements of the pair will be put in the result. No element from either <A HREF="26_1_Glossary.html#list"
|
|
><EM CLASS="term"
|
|
>list</EM
|
|
></A
|
|
> appears in the result that does not <A HREF="26_1_Glossary.html#satisfy_the_test"
|
|
><EM CLASS="term"
|
|
>satisfy the test</EM
|
|
></A
|
|
> for an element from the other <A HREF="26_1_Glossary.html#list"
|
|
><EM CLASS="term"
|
|
>list</EM
|
|
></A
|
|
>. If one of the <A HREF="26_1_Glossary.html#list"
|
|
><EM CLASS="term"
|
|
>lists</EM
|
|
></A
|
|
> contains duplicate elements, there may be duplication in the result. </P
|
|
><P CLASS="j"
|
|
>There is no guarantee that the order of elements in the result will reflect the ordering of the arguments in any particular way. The result <A HREF="26_1_Glossary.html#list"
|
|
><EM CLASS="term"
|
|
>list</EM
|
|
></A
|
|
> may share cells with, or be <A HREF="f_eq.html" CLASS="funref"
|
|
><B
|
|
>eq</B
|
|
></A
|
|
> to, either <VAR CLASS="param"
|
|
>list-1</VAR
|
|
> or <VAR CLASS="param"
|
|
>list-2</VAR
|
|
> if appropriate.</P
|
|
></DD
|
|
><DT
|
|
><B
|
|
>Examples</B
|
|
></DT
|
|
><DD
|
|
><PRE CLASS="screen"
|
|
> (setq list1 (list 1 1 2 3 4 a b c "A" "B" "C" "d")
|
|
list2 (list 1 4 5 b c d "a" "B" "c" "D"))
|
|
<SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (1 4 5 B C D "a" "B" "c" "D")
|
|
(intersection list1 list2) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (C B 4 1 1)
|
|
(intersection list1 list2 :test 'equal) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> ("B" C B 4 1 1)
|
|
(intersection list1 list2 :test #'equalp) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> ("d" "C" "B" "A" C B 4 1 1)
|
|
(nintersection list1 list2) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (1 1 4 B C)
|
|
list1 <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> <A HREF="26_1_Glossary.html#implementation-dependent"
|
|
><EM CLASS="term"
|
|
>implementation-dependent</EM
|
|
></A
|
|
> ;<I CLASS="i"
|
|
><I
|
|
>e.g.</I
|
|
></I
|
|
>, (1 1 4 B C)
|
|
list2 <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> <A HREF="26_1_Glossary.html#implementation-dependent"
|
|
><EM CLASS="term"
|
|
>implementation-dependent</EM
|
|
></A
|
|
> ;<I CLASS="i"
|
|
><I
|
|
>e.g.</I
|
|
></I
|
|
>, (1 4 5 B C D "a" "B" "c" "D")
|
|
(setq list1 (copy-list '((1 . 2) (2 . 3) (3 . 4) (4 . 5))))
|
|
<SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> ((1 . 2) (2 . 3) (3 . 4) (4 . 5))
|
|
(setq list2 (copy-list '((1 . 3) (2 . 4) (3 . 6) (4 . 8))))
|
|
<SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> ((1 . 3) (2 . 4) (3 . 6) (4 . 8))
|
|
(nintersection list1 list2 :key #'cdr) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> ((2 . 3) (3 . 4))
|
|
list1 <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> <A HREF="26_1_Glossary.html#implementation-dependent"
|
|
><EM CLASS="term"
|
|
>implementation-dependent</EM
|
|
></A
|
|
> ;<I CLASS="i"
|
|
><I
|
|
>e.g.</I
|
|
></I
|
|
>, ((1 . 2) (2 . 3) (3 . 4))
|
|
list2 <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> <A HREF="26_1_Glossary.html#implementation-dependent"
|
|
><EM CLASS="term"
|
|
>implementation-dependent</EM
|
|
></A
|
|
> ;<I CLASS="i"
|
|
><I
|
|
>e.g.</I
|
|
></I
|
|
>, ((1 . 3) (2 . 4) (3 . 6) (4 . 8))</PRE
|
|
></DD
|
|
><DT
|
|
><B
|
|
>Side Effects</B
|
|
></DT
|
|
><DD
|
|
><P CLASS="j"
|
|
><A HREF="f_intersection.html" CLASS="funref"
|
|
><B
|
|
>nintersection</B
|
|
></A
|
|
> can modify <VAR CLASS="param"
|
|
>list-1</VAR
|
|
>, but not <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="f_union.html" CLASS="funref"
|
|
><B
|
|
>union</B
|
|
></A
|
|
>, <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_intersection.html" CLASS="funref"
|
|
><B
|
|
>nintersection</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_remf.html" CLASS="prev"
|
|
>←</A
|
|
><A HREF="f_adjoin.html" CLASS="next"
|
|
>→</A
|
|
></DIV
|
|
><DIV CLASS="trail"
|
|
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
|
|
></DIV
|
|
></DIV
|
|
><SCRIPT
|
|
>domReady();</SCRIPT
|
|
></BODY
|
|
></HTML
|
|
> |