| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 2 |
<html> |
| 3 |
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ --> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 6 |
<title>reverse (ANSI and GNU Common Lisp Document)</title> |
| 7 |
|
| 8 |
<meta name="description" content="reverse (ANSI and GNU Common Lisp Document)"> |
| 9 |
<meta name="keywords" content="reverse (ANSI and GNU Common Lisp Document)"> |
| 10 |
<meta name="resource-type" content="document"> |
| 11 |
<meta name="distribution" content="global"> |
| 12 |
<meta name="Generator" content="makeinfo"> |
| 13 |
<link href="index.html" rel="start" title="Top"> |
| 14 |
<link href="Sequences-Dictionary.html" rel="up" title="Sequences Dictionary"> |
| 15 |
<link href="sort.html" rel="next" title="sort"> |
| 16 |
<link href="length.html" rel="prev" title="length"> |
| 17 |
<style type="text/css"> |
| 18 |
<!-- |
| 19 |
a.summary-letter {text-decoration: none} |
| 20 |
blockquote.indentedblock {margin-right: 0em} |
| 21 |
div.display {margin-left: 3.2em} |
| 22 |
div.example {margin-left: 3.2em} |
| 23 |
div.lisp {margin-left: 3.2em} |
| 24 |
kbd {font-style: oblique} |
| 25 |
pre.display {font-family: inherit} |
| 26 |
pre.format {font-family: inherit} |
| 27 |
pre.menu-comment {font-family: serif} |
| 28 |
pre.menu-preformatted {font-family: serif} |
| 29 |
span.nolinebreak {white-space: nowrap} |
| 30 |
span.roman {font-family: initial; font-weight: normal} |
| 31 |
span.sansserif {font-family: sans-serif; font-weight: normal} |
| 32 |
ul.no-bullet {list-style: none} |
| 33 |
--> |
| 34 |
</style> |
| 35 |
|
| 36 |
|
| 37 |
</head> |
| 38 |
|
| 39 |
<body lang="en"> |
| 40 |
<span id="reverse"></span><div class="header"> |
| 41 |
<p> |
| 42 |
Next: <a href="sort.html" accesskey="n" rel="next">sort</a>, Previous: <a href="length.html" accesskey="p" rel="prev">length</a>, Up: <a href="Sequences-Dictionary.html" accesskey="u" rel="up">Sequences Dictionary</a> </p> |
| 43 |
</div> |
| 44 |
<hr> |
| 45 |
<span id="reverse_002c-nreverse-_005bFunction_005d"></span><h4 class="subsection">17.3.12 reverse, nreverse [Function]</h4> |
| 46 |
|
| 47 |
<p><code>reverse</code> <i>sequence</i> ⇒ <i>reversed-sequence</i> |
| 48 |
</p> |
| 49 |
<p><code>nreverse</code> <i>sequence</i> ⇒ <i>reversed-sequence</i> |
| 50 |
</p> |
| 51 |
<span id="Arguments-and-Values_003a_003a-364"></span><h4 class="subsubheading">Arguments and Values::</h4> |
| 52 |
|
| 53 |
<p><i>sequence</i>—a <i>proper sequence</i>. |
| 54 |
</p> |
| 55 |
<p><i>reversed-sequence</i>—a <i>sequence</i>. |
| 56 |
</p> |
| 57 |
<span id="Description_003a_003a-479"></span><h4 class="subsubheading">Description::</h4> |
| 58 |
|
| 59 |
<p><b>reverse</b> and <b>nreverse</b> return a new <i>sequence</i> |
| 60 |
of the same kind as <i>sequence</i>, containing the same <i>elements</i>, |
| 61 |
but in reverse order. |
| 62 |
</p> |
| 63 |
<p><b>reverse</b> and <b>nreverse</b> differ in that <b>reverse</b> |
| 64 |
always creates and returns a new <i>sequence</i>, whereas <b>nreverse</b> |
| 65 |
might modify and return the given <i>sequence</i>. <b>reverse</b> never |
| 66 |
modifies the given <i>sequence</i>. |
| 67 |
</p> |
| 68 |
<p>For <b>reverse</b>, if <i>sequence</i> is a <i>vector</i>, |
| 69 |
the result is a <i>fresh</i> <i>simple array</i> of <i>rank</i> one |
| 70 |
that has the same <i>actual array element type</i> as <i>sequence</i>. |
| 71 |
If <i>sequence</i> is a <i>list</i>, the result is a <i>fresh</i> <i>list</i>. |
| 72 |
</p> |
| 73 |
<p>For <b>nreverse</b>, if <i>sequence</i> is a <i>vector</i>, |
| 74 |
the result is a <i>vector</i> |
| 75 |
that has the same <i>actual array element type</i> as <i>sequence</i>. |
| 76 |
If <i>sequence</i> is a <i>list</i>, the result is a <i>list</i>. |
| 77 |
</p> |
| 78 |
<p>For <b>nreverse</b>, |
| 79 |
<i>sequence</i> might be destroyed and re-used to produce the result. |
| 80 |
The result might or might not be <i>identical</i> to <i>sequence</i>. |
| 81 |
</p> |
| 82 |
<p>Specifically, when <i>sequence</i> is a <i>list</i>, |
| 83 |
<b>nreverse</b> is permitted to <b>setf</b> any part, <b>car</b> or <b>cdr</b>, |
| 84 |
of any <i>cons</i> that is part of the <i>list structure</i> of <i>sequence</i>. |
| 85 |
When <i>sequence</i> is a <i>vector</i>, |
| 86 |
<b>nreverse</b> is permitted to re-order the elements of <i>sequence</i> |
| 87 |
in order to produce the resulting <i>vector</i>. |
| 88 |
</p> |
| 89 |
<span id="Examples_003a_003a-346"></span><h4 class="subsubheading">Examples::</h4> |
| 90 |
<div class="example"> |
| 91 |
<pre class="example"> (setq str "abc") ⇒ "abc" |
| 92 |
(reverse str) ⇒ "cba" |
| 93 |
str ⇒ "abc" |
| 94 |
(setq str (copy-seq str)) ⇒ "abc" |
| 95 |
(nreverse str) ⇒ "cba" |
| 96 |
str ⇒ <i>implementation-dependent</i> |
| 97 |
(setq l (list 1 2 3)) ⇒ (1 2 3) |
| 98 |
(nreverse l) ⇒ (3 2 1) |
| 99 |
l ⇒ <i>implementation-dependent</i> |
| 100 |
</pre></div> |
| 101 |
|
| 102 |
<span id="Side-Effects_003a_003a-52"></span><h4 class="subsubheading">Side Effects::</h4> |
| 103 |
|
| 104 |
<p><b>nreverse</b> might either create a new <i>sequence</i>, |
| 105 |
modify the argument <i>sequence</i>, or both. |
| 106 |
(<b>reverse</b> does not modify <i>sequence</i>.) |
| 107 |
</p> |
| 108 |
<span id="Exceptional-Situations_003a_003a-160"></span><h4 class="subsubheading">Exceptional Situations::</h4> |
| 109 |
|
| 110 |
<p>Should be prepared to signal an error of <i>type</i> <b>type-error</b> |
| 111 |
if <i>sequence</i> is not a <i>proper sequence</i>. |
| 112 |
</p> |
| 113 |
<hr> |
| 114 |
<div class="header"> |
| 115 |
<p> |
| 116 |
Next: <a href="sort.html" accesskey="n" rel="next">sort</a>, Previous: <a href="length.html" accesskey="p" rel="prev">length</a>, Up: <a href="Sequences-Dictionary.html" accesskey="u" rel="up">Sequences Dictionary</a> </p> |
| 117 |
</div> |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
</body> |
| 122 |
</html> |