376 lines
No EOL
8.2 KiB
HTML
376 lines
No EOL
8.2 KiB
HTML
<!DOCTYPE HTML>
|
|
<HTML LANG="en-us"
|
|
><HEAD
|
|
><TITLE
|
|
>map-into | Common Lisp Nova Spec</TITLE
|
|
><META CHARSET="US-ASCII"
|
|
><LINK REL="canonical" HREF="f_map-into.html"
|
|
><LINK REL="next" HREF="f_reduce.html" TYPE="text/html" TITLE="reduce"
|
|
><LINK REL="prev" HREF="f_map.html" TYPE="text/html" TITLE="map"
|
|
><LINK REL="up" HREF="17_3_Sequences_Dictionary.html" TYPE="text/html" TITLE="17.3 Sequences 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="17_Sequences.html"
|
|
>17. Sequences</A
|
|
></SPAN
|
|
> <SPAN CLASS="breadcrumb-item"
|
|
>→ <A HREF="17_3_Sequences_Dictionary.html"
|
|
>17.3 Sequences Dictionary</A
|
|
></SPAN
|
|
> <SPAN CLASS="breadcrumb-item"
|
|
>→ <A HREF="f_map-into.html"
|
|
>map-into</A
|
|
></SPAN
|
|
></DIV
|
|
><DIV CLASS="apropos"
|
|
><DIV CLASS="apropos-io"
|
|
><A HREF="f_map.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_reduce.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="map-into"
|
|
></SPAN
|
|
><B
|
|
>map-into</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
|
|
>map-into</B
|
|
> <SPAN CLASS="cmssi"
|
|
>result-sequence</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>function</SPAN
|
|
> <SPAN CLASS="cmtt"
|
|
>&rest</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>sequences</SPAN
|
|
> <SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
> <SPAN CLASS="cmssi"
|
|
>result-sequence</SPAN
|
|
></P
|
|
></DD
|
|
><DT
|
|
><B
|
|
>Arguments and Values</B
|
|
></DT
|
|
><DD
|
|
><P CLASS="j"
|
|
><VAR CLASS="param"
|
|
>result-sequence</VAR
|
|
> — a <A HREF="26_1_Glossary.html#proper_sequence"
|
|
><EM CLASS="term"
|
|
>proper sequence</EM
|
|
></A
|
|
>. </P
|
|
><P CLASS="j"
|
|
><VAR CLASS="param"
|
|
>function</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 as many <A HREF="26_1_Glossary.html#argument"
|
|
><EM CLASS="term"
|
|
>arguments</EM
|
|
></A
|
|
> as there are <VAR CLASS="param"
|
|
>sequences</VAR
|
|
>. </P
|
|
><P CLASS="j"
|
|
><VAR CLASS="param"
|
|
>sequence</VAR
|
|
> — a <A HREF="26_1_Glossary.html#proper_sequence"
|
|
><EM CLASS="term"
|
|
>proper sequence</EM
|
|
></A
|
|
>.</P
|
|
></DD
|
|
><DT
|
|
><B
|
|
>Description</B
|
|
></DT
|
|
><DD
|
|
><P CLASS="j"
|
|
>Destructively modifies <VAR CLASS="param"
|
|
>result-sequence</VAR
|
|
> to contain the results of applying <VAR CLASS="param"
|
|
>function</VAR
|
|
> to each element in the argument <VAR CLASS="param"
|
|
>sequences</VAR
|
|
> in turn. </P
|
|
><P CLASS="j"
|
|
><VAR CLASS="param"
|
|
>result-sequence</VAR
|
|
> and each element of <VAR CLASS="param"
|
|
>sequences</VAR
|
|
> can each be either a <A HREF="26_1_Glossary.html#list"
|
|
><EM CLASS="term"
|
|
>list</EM
|
|
></A
|
|
> or a <A HREF="26_1_Glossary.html#vector"
|
|
><EM CLASS="term"
|
|
>vector</EM
|
|
></A
|
|
>. If <VAR CLASS="param"
|
|
>result-sequence</VAR
|
|
> and each element of <VAR CLASS="param"
|
|
>sequences</VAR
|
|
> are not all the same length, the iteration terminates when the shortest <A HREF="26_1_Glossary.html#sequence"
|
|
><EM CLASS="term"
|
|
>sequence</EM
|
|
></A
|
|
> (of any of the <VAR CLASS="param"
|
|
>sequences</VAR
|
|
> or the <VAR CLASS="param"
|
|
>result-sequence</VAR
|
|
>) is exhausted. If <VAR CLASS="param"
|
|
>result-sequence</VAR
|
|
> is a <A HREF="26_1_Glossary.html#vector"
|
|
><EM CLASS="term"
|
|
>vector</EM
|
|
></A
|
|
> with a <A HREF="26_1_Glossary.html#fill_pointer"
|
|
><EM CLASS="term"
|
|
>fill pointer</EM
|
|
></A
|
|
>, the <A HREF="26_1_Glossary.html#fill_pointer"
|
|
><EM CLASS="term"
|
|
>fill pointer</EM
|
|
></A
|
|
> is ignored when deciding how many iterations to perform, and afterwards the <A HREF="26_1_Glossary.html#fill_pointer"
|
|
><EM CLASS="term"
|
|
>fill pointer</EM
|
|
></A
|
|
> is set to the number of times <VAR CLASS="param"
|
|
>function</VAR
|
|
> was applied. If <VAR CLASS="param"
|
|
>result-sequence</VAR
|
|
> is longer than the shortest element of <VAR CLASS="param"
|
|
>sequences</VAR
|
|
>, extra elements at the end of <VAR CLASS="param"
|
|
>result-sequence</VAR
|
|
> are left unchanged. If <VAR CLASS="param"
|
|
>result-sequence</VAR
|
|
> is <SPAN CLASS="misc"
|
|
><B
|
|
>nil</B
|
|
></SPAN
|
|
>, <A HREF="f_map-into.html" CLASS="funref"
|
|
><B
|
|
>map-into</B
|
|
></A
|
|
> immediately returns <SPAN CLASS="misc"
|
|
><B
|
|
>nil</B
|
|
></SPAN
|
|
>, since <SPAN CLASS="misc"
|
|
><B
|
|
>nil</B
|
|
></SPAN
|
|
> is a <A HREF="26_1_Glossary.html#sequence"
|
|
><EM CLASS="term"
|
|
>sequence</EM
|
|
></A
|
|
> of length zero. </P
|
|
><P CLASS="j"
|
|
>If <VAR CLASS="param"
|
|
>function</VAR
|
|
> has side effects, it can count on being called first on all of the elements with index 0, then on all of those numbered 1, and so on.</P
|
|
></DD
|
|
><DT
|
|
><B
|
|
>Examples</B
|
|
></DT
|
|
><DD
|
|
><PRE CLASS="screen"
|
|
>(setq a (list 1 2 3 4) b (list 10 10 10 10)) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (10 10 10 10)
|
|
(map-into a #'+ a b) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (11 12 13 14)
|
|
a <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (11 12 13 14)
|
|
b <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (10 10 10 10)
|
|
(setq k '(one two three)) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (ONE TWO THREE)
|
|
(map-into a #'cons k a) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> ((ONE . 11) (TWO . 12) (THREE . 13) 14)
|
|
(map-into a #'gensym) <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (#:G9090 #:G9091 #:G9092 #:G9093)
|
|
a <SPAN CLASS="cmsy"
|
|
><SPAN CLASS="arrow"
|
|
>→</SPAN
|
|
></SPAN
|
|
> (#:G9090 #:G9091 #:G9092 #:G9093)</PRE
|
|
></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"
|
|
>result-sequence</VAR
|
|
> is not a <A HREF="26_1_Glossary.html#proper_sequence"
|
|
><EM CLASS="term"
|
|
>proper sequence</EM
|
|
></A
|
|
>. 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"
|
|
>sequence</VAR
|
|
> is not a <A HREF="26_1_Glossary.html#proper_sequence"
|
|
><EM CLASS="term"
|
|
>proper sequence</EM
|
|
></A
|
|
>.</P
|
|
></DD
|
|
><DT
|
|
><B
|
|
>Notes</B
|
|
></DT
|
|
><DD
|
|
><P CLASS="j"
|
|
><A HREF="f_map-into.html" CLASS="funref"
|
|
><B
|
|
>map-into</B
|
|
></A
|
|
> differs from <A HREF="f_map.html" CLASS="funref"
|
|
><B
|
|
>map</B
|
|
></A
|
|
> in that it modifies an existing <A HREF="26_1_Glossary.html#sequence"
|
|
><EM CLASS="term"
|
|
>sequence</EM
|
|
></A
|
|
> rather than creating a new one. In addition, <A HREF="f_map-into.html" CLASS="funref"
|
|
><B
|
|
>map-into</B
|
|
></A
|
|
> can be called with only two arguments, while <A HREF="f_map.html" CLASS="funref"
|
|
><B
|
|
>map</B
|
|
></A
|
|
> requires at least three arguments. </P
|
|
><P CLASS="j"
|
|
><A HREF="f_map-into.html" CLASS="funref"
|
|
><B
|
|
>map-into</B
|
|
></A
|
|
> could be defined by:</P
|
|
><PRE CLASS="screen"
|
|
>(defun map-into (result-sequence function &rest sequences)
|
|
(loop for index below (apply #'min
|
|
(length result-sequence)
|
|
(mapcar #'length sequences))
|
|
do (setf (elt result-sequence index)
|
|
(apply function
|
|
(mapcar #'(lambda (seq) (elt seq index))
|
|
sequences))))
|
|
result-sequence)</PRE
|
|
></DD
|
|
></DL
|
|
></DIV
|
|
></DIV
|
|
><DIV CLASS="footer"
|
|
><DIV CLASS="btmnav"
|
|
><A HREF="f_map.html" CLASS="prev"
|
|
>←</A
|
|
><A HREF="f_reduce.html" CLASS="next"
|
|
>→</A
|
|
></DIV
|
|
><DIV CLASS="trail"
|
|
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
|
|
></DIV
|
|
></DIV
|
|
><SCRIPT
|
|
>domReady();</SCRIPT
|
|
></BODY
|
|
></HTML
|
|
> |