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>replace (ANSI and GNU Common Lisp Document)</title>
<meta name="description" content="replace (ANSI and GNU Common Lisp Document)">
<meta name="keywords" content="replace (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="Sequences-Dictionary.html" rel="up" title="Sequences Dictionary">
<link href="substitute.html" rel="next" title="substitute">
<link href="mismatch.html" rel="prev" title="mismatch">
<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="replace"></span><div class="header">
<p>
Next: <a href="substitute.html" accesskey="n" rel="next">substitute</a>, Previous: <a href="mismatch.html" accesskey="p" rel="prev">mismatch</a>, Up: <a href="Sequences-Dictionary.html" accesskey="u" rel="up">Sequences Dictionary</a> </p>
</div>
<hr>
<span id="replace-_005bFunction_005d"></span><h4 class="subsection">17.3.18 replace [Function]</h4>
<p><code>replace</code> <i>sequence-1 sequence-2 <span class="roman">&key</span> start1 end1 start2 end2</i> ⇒ <i>sequence-1</i>
</p>
<span id="Arguments-and-Values_003a_003a-370"></span><h4 class="subsubheading">Arguments and Values::</h4>
<p><i>sequence-1</i>—a <i>sequence</i>.
</p>
<p><i>sequence-2</i>—a <i>sequence</i>.
</p>
<p><i>start1</i>, <i>end1</i>—<i>bounding index designators</i> of <i>sequence-1</i>.
The defaults for <i>start1</i> and <i>end1</i> are <tt>0</tt> and <b>nil</b>, respectively.
</p>
<p><i>start2</i>, <i>end2</i>—<i>bounding index designators</i> of <i>sequence-2</i>.
The defaults for <i>start2</i> and <i>end2</i> are <tt>0</tt> and <b>nil</b>, respectively.
</p>
<span id="Description_003a_003a-485"></span><h4 class="subsubheading">Description::</h4>
<p>Destructively modifies <i>sequence-1</i>
by replacing the <i>elements</i> of <i>subsequence-1</i>
<i>bounded</i> by <i>start1</i> and <i>end1</i>
with the <i>elements</i> of <i>subsequence-2</i>
<i>bounded</i> by <i>start2</i> and <i>end2</i>.
</p>
<p><i>Sequence-1</i> is destructively modified by copying successive
<i>elements</i> into it from <i>sequence-2</i>.
<i>Elements</i> of the subsequence of <i>sequence-2</i>
<i>bounded</i> by <i>start2</i> and <i>end2</i>
are copied into the subsequence of <i>sequence-1</i>
<i>bounded</i> by <i>start1</i> and <i>end1</i>.
If these subsequences are not of the same length,
then the shorter length determines how many <i>elements</i> are copied;
the extra <i>elements</i> near the end of the longer subsequence
are not involved in the operation.
The number of elements copied can be expressed as:
</p>
<div class="example">
<pre class="example"> (min (- <i>end1</i> <i>start1</i>) (- <i>end2</i> <i>start2</i>))
</pre></div>
<p>If <i>sequence-1</i> and <i>sequence-2</i> are the <i>same</i> <i>object</i>
and the region being modified overlaps the region being copied
from, then it is as if the entire source region were copied to another
place and only then copied back into the target region.
However, if <i>sequence-1</i> and <i>sequence-2</i> are not the same,
but the region being modified overlaps the region being copied from
(perhaps because of shared list structure or displaced <i>arrays</i>),
then after the <b>replace</b> operation
the subsequence of <i>sequence-1</i> being modified will have
unpredictable contents.
It is an error if the elements of <i>sequence-2</i> are not of a
<i>type</i> that can be stored into <i>sequence-1</i>.
</p>
<span id="Examples_003a_003a-352"></span><h4 class="subsubheading">Examples::</h4>
<div class="example">
<pre class="example"> (replace "abcdefghij" "0123456789" :start1 4 :end1 7 :start2 4)
⇒ "abcd456hij"
(setq lst "012345678") ⇒ "012345678"
(replace lst lst :start1 2 :start2 0) ⇒ "010123456"
lst ⇒ "010123456"
</pre></div>
<span id="Side-Effects_003a_003a-53"></span><h4 class="subsubheading">Side Effects::</h4>
<p>The <i>sequence-1</i> is modified.
</p>
<span id="See-Also_003a_003a-395"></span><h4 class="subsubheading">See Also::</h4>
<p><a href="fill.html">fill</a>
</p>
<hr>
<div class="header">
<p>
Next: <a href="substitute.html" accesskey="n" rel="next">substitute</a>, Previous: <a href="mismatch.html" accesskey="p" rel="prev">mismatch</a>, Up: <a href="Sequences-Dictionary.html" accesskey="u" rel="up">Sequences Dictionary</a> </p>
</div>
</body>
</html>
|