| 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>map-into (ANSI and GNU Common Lisp Document)</title> |
| 7 |
|
| 8 |
<meta name="description" content="map-into (ANSI and GNU Common Lisp Document)"> |
| 9 |
<meta name="keywords" content="map-into (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="reduce.html" rel="next" title="reduce"> |
| 16 |
<link href="map.html" rel="prev" title="map"> |
| 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="map_002dinto"></span><div class="header"> |
| 41 |
<p> |
| 42 |
Next: <a href="reduce.html" accesskey="n" rel="next">reduce</a>, Previous: <a href="map.html" accesskey="p" rel="prev">map</a>, Up: <a href="Sequences-Dictionary.html" accesskey="u" rel="up">Sequences Dictionary</a> </p> |
| 43 |
</div> |
| 44 |
<hr> |
| 45 |
<span id="map_002dinto-_005bFunction_005d"></span><h4 class="subsection">17.3.8 map-into [Function]</h4> |
| 46 |
|
| 47 |
<p><code>map-into</code> <i>result-sequence function <span class="roman">&rest</span> sequences</i> ⇒ <i>result-sequence</i> |
| 48 |
</p> |
| 49 |
<span id="Arguments-and-Values_003a_003a-360"></span><h4 class="subsubheading">Arguments and Values::</h4> |
| 50 |
|
| 51 |
<p><i>result-sequence</i>—a <i>proper sequence</i>. |
| 52 |
</p> |
| 53 |
<p><i>function</i>—a <i>designator</i> for a <i>function</i> |
| 54 |
of as many <i>arguments</i> as there are <i>sequences</i>. |
| 55 |
</p> |
| 56 |
<p><i>sequence</i>—a <i>proper sequence</i>. |
| 57 |
</p> |
| 58 |
<span id="Description_003a_003a-475"></span><h4 class="subsubheading">Description::</h4> |
| 59 |
|
| 60 |
<p>Destructively modifies <i>result-sequence</i> to contain the results of |
| 61 |
applying <i>function</i> to each element in the argument <i>sequences</i> |
| 62 |
in turn. |
| 63 |
</p> |
| 64 |
<p><i>result-sequence</i> and each element of <i>sequences</i> can each be |
| 65 |
either a <i>list</i> or a <i>vector</i>. |
| 66 |
If <i>result-sequence</i> and each element of <i>sequences</i> are not all |
| 67 |
the same length, the iteration terminates when the shortest <i>sequence</i> |
| 68 |
(of any of the <i>sequences</i> or the <i>result-sequence</i>) |
| 69 |
is exhausted. |
| 70 |
If <i>result-sequence</i> is a <i>vector</i> with a |
| 71 |
<i>fill pointer</i>, the <i>fill pointer</i> is ignored when deciding how |
| 72 |
many iterations to perform, and afterwards the <i>fill pointer</i> is set to |
| 73 |
the number of times <i>function</i> was applied. |
| 74 |
If <i>result-sequence</i> is longer than the shortest element of <i>sequences</i>, |
| 75 |
extra elements at the end of <i>result-sequence</i> are left unchanged. |
| 76 |
If <i>result-sequence</i> is <b>nil</b>, <b>map-into</b> immediately returns |
| 77 |
<b>nil</b>, since <b>nil</b> is a <i>sequence</i> of length zero. |
| 78 |
</p> |
| 79 |
<p>If <i>function</i> has side effects, it can count on being called |
| 80 |
first on all of the elements with index 0, then on all of those |
| 81 |
numbered 1, and so on. |
| 82 |
</p> |
| 83 |
<span id="Examples_003a_003a-342"></span><h4 class="subsubheading">Examples::</h4> |
| 84 |
|
| 85 |
<div class="example"> |
| 86 |
<pre class="example"> (setq a (list 1 2 3 4) b (list 10 10 10 10)) ⇒ (10 10 10 10) |
| 87 |
(map-into a #'+ a b) ⇒ (11 12 13 14) |
| 88 |
a ⇒ (11 12 13 14) |
| 89 |
b ⇒ (10 10 10 10) |
| 90 |
(setq k '(one two three)) ⇒ (ONE TWO THREE) |
| 91 |
(map-into a #'cons k a) ⇒ ((ONE . 11) (TWO . 12) (THREE . 13) 14) |
| 92 |
(map-into a #'gensym) ⇒ (#:G9090 #:G9091 #:G9092 #:G9093) |
| 93 |
a ⇒ (#:G9090 #:G9091 #:G9092 #:G9093) |
| 94 |
</pre></div> |
| 95 |
|
| 96 |
<span id="Exceptional-Situations_003a_003a-156"></span><h4 class="subsubheading">Exceptional Situations::</h4> |
| 97 |
|
| 98 |
<p>Should be prepared to signal an error of <i>type</i> <b>type-error</b> |
| 99 |
if <i>result-sequence</i> is not a <i>proper sequence</i>. |
| 100 |
Should be prepared to signal an error of <i>type</i> <b>type-error</b> |
| 101 |
if <i>sequence</i> is not a <i>proper sequence</i>. |
| 102 |
</p> |
| 103 |
<span id="Notes_003a_003a-260"></span><h4 class="subsubheading">Notes::</h4> |
| 104 |
|
| 105 |
<p><b>map-into</b> differs from <b>map</b> in that it modifies an |
| 106 |
existing <i>sequence</i> rather than creating a new one. |
| 107 |
In addition, <b>map-into</b> can be called with only two |
| 108 |
arguments, while <b>map</b> requires at least three arguments. |
| 109 |
</p> |
| 110 |
<p><b>map-into</b> could be defined by: |
| 111 |
</p> |
| 112 |
<div class="example"> |
| 113 |
<pre class="example"> (defun map-into (result-sequence function &rest sequences) |
| 114 |
(loop for index below (apply #'min |
| 115 |
(length result-sequence) |
| 116 |
(mapcar #'length sequences)) |
| 117 |
do (setf (elt result-sequence index) |
| 118 |
(apply function |
| 119 |
(mapcar #'(lambda (seq) (elt seq index)) |
| 120 |
sequences)))) |
| 121 |
result-sequence) |
| 122 |
</pre></div> |
| 123 |
|
| 124 |
<hr> |
| 125 |
<div class="header"> |
| 126 |
<p> |
| 127 |
Next: <a href="reduce.html" accesskey="n" rel="next">reduce</a>, Previous: <a href="map.html" accesskey="p" rel="prev">map</a>, Up: <a href="Sequences-Dictionary.html" accesskey="u" rel="up">Sequences Dictionary</a> </p> |
| 128 |
</div> |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
</body> |
| 133 |
</html> |