1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>adjoin (ANSI and GNU Common Lisp Document)</title>
<meta name="description" content="adjoin (ANSI and GNU Common Lisp Document)">
<meta name="keywords" content="adjoin (ANSI and GNU Common Lisp Document)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="Conses-Dictionary.html" rel="up" title="Conses Dictionary">
<link href="pushnew.html" rel="next" title="pushnew">
<link href="intersection.html" rel="prev" title="intersection">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en">
<span id="adjoin"></span><div class="header">
<p>
Next: <a href="pushnew.html" accesskey="n" rel="next">pushnew</a>, Previous: <a href="intersection.html" accesskey="p" rel="prev">intersection</a>, Up: <a href="Conses-Dictionary.html" accesskey="u" rel="up">Conses Dictionary</a> </p>
</div>
<hr>
<span id="adjoin-_005bFunction_005d"></span><h4 class="subsection">14.2.44 adjoin [Function]</h4>
<p><code>adjoin</code> <i>item list <span class="roman">&key</span> key test test-not</i> ⇒ <i>new-list</i>
</p>
<span id="Arguments-and-Values_003a_003a-313"></span><h4 class="subsubheading">Arguments and Values::</h4>
<p><i>item</i>—an <i>object</i>.
</p>
<p><i>list</i>—a <i>proper list</i>.
</p>
<p><i>test</i>—a <i>designator</i> for a <i>function</i> of two <i>arguments</i>
that returns a <i>generalized boolean</i>.
</p>
<p><i>test-not</i>—a <i>designator</i> for
a <i>function</i> of two <i>arguments</i>
that returns a <i>generalized boolean</i>.
</p>
<p><i>key</i>—a <i>designator</i> for a <i>function</i> of one argument,
or <b>nil</b>.
</p>
<p><i>new-list</i>—a <i>list</i>.
</p>
<span id="Description_003a_003a-414"></span><h4 class="subsubheading">Description::</h4>
<p>Tests whether <i>item</i> is the same as an existing element of <i>list</i>.
If the <i>item</i> is not an existing element,
<b>adjoin</b> adds it to <i>list</i> (as if by <b>cons</b>)
and returns the resulting <i>list</i>;
otherwise, nothing is added and the original <i>list</i> is returned.
</p>
<p>The <i>test</i>, <i>test-not</i>, and <i>key</i>
affect how it is determined whether <i>item</i> is the same as an <i>element</i> of <i>list</i>.
For details, see <a href="Satisfying-a-Two_002dArgument-Test.html">Satisfying a Two-Argument Test</a>.\ifvmode\else\endgraf
\ifdim \prevdepth>-1000pt
\NIS\parskip \normalparskip\relax\fi
</p>
<span id="Examples_003a_003a-297"></span><h4 class="subsubheading">Examples::</h4>
<div class="example">
<pre class="example"> (setq slist '()) ⇒ NIL
(adjoin 'a slist) ⇒ (A)
slist ⇒ NIL
(setq slist (adjoin '(test-item 1) slist)) ⇒ ((TEST-ITEM 1))
(adjoin '(test-item 1) slist) ⇒ ((TEST-ITEM 1) (TEST-ITEM 1))
(adjoin '(test-item 1) slist :test 'equal) ⇒ ((TEST-ITEM 1))
(adjoin '(new-test-item 1) slist :key #'cadr) ⇒ ((TEST-ITEM 1))
(adjoin '(new-test-item 1) slist) ⇒ ((NEW-TEST-ITEM 1) (TEST-ITEM 1))
</pre></div>
<span id="Exceptional-Situations_003a_003a-133"></span><h4 class="subsubheading">Exceptional Situations::</h4>
<p>Should be prepared to signal an error of <i>type</i> <b>type-error</b>
if <i>list</i> is not a <i>proper list</i>.
</p>
<span id="See-Also_003a_003a-338"></span><h4 class="subsubheading">See Also::</h4>
<p><a href="pushnew.html">pushnew</a>
,
</p>
<p><a href="Traversal-Rules-and-Side-Effects.html">Traversal Rules and Side Effects</a>
</p>
<span id="Notes_003a_003a-224"></span><h4 class="subsubheading">Notes::</h4>
<p>The <tt>:test-not</tt> parameter is deprecated.
</p>
<div class="example">
<pre class="example"> (adjoin item list :key fn)
≡ (if (member (fn item) list :key fn) list (cons item list))
</pre></div>
<hr>
<div class="header">
<p>
Next: <a href="pushnew.html" accesskey="n" rel="next">pushnew</a>, Previous: <a href="intersection.html" accesskey="p" rel="prev">intersection</a>, Up: <a href="Conses-Dictionary.html" accesskey="u" rel="up">Conses Dictionary</a> </p>
</div>
</body>
</html>
|