1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Issues/iss239_w.htm

133 lines
7.3 KiB
HTML
Raw Permalink Normal View History

2024-04-01 10:24:07 +02:00
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
<HTML>
<HEAD>
<TITLE>CLHS: Issue MAP-INTO Writeup</TITLE>
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
<LINK REL=TOP HREF="../Front/index.htm">
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
<LINK REL=PREV HREF="../Issues/iss238_w.htm">
<LINK REL=UP HREF="../Issues/iss239.htm">
<LINK REL=NEXT HREF="../Issues/iss240_w.htm">
</HEAD>
<BODY>
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="../Issues/iss238_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss239.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss240_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue MAP-INTO Writeup</H2>
<PRE><B>Status:</B> Passed, Jun 89 X3J13<P>
<B>Issue:</B> <A REL=DEFINITION HREF="../Body/f_map_in.htm#map-into"><B>MAP-INTO</B></A><P>
<B>References:</B> none<P>
Related issues: BIT-ARRAY-FUNCTIONS<P>
<B>Category:</B> ADDITION<P>
<B>Edit history:</B> 23-May-89, version 1 by Moon<P>
19-Jun-89, version 2 by Moon (fix arglist)<P>
23-Jun-89, version 3 by Moon (include BarMar's suggestions)<P>
<P>
<B>Problem description:<P>
</B><P>
The function <A REL=DEFINITION HREF="../Body/f_map.htm#map"><B>MAP</B></A> is very useful but can be a source of inefficiency<P>
because it conses the result. Sometimes the user has storage<P>
already allocated in which the result could be stored.<P>
<P>
<B>Proposal (MAP-INTO:ADD-FUNCTION):<P>
</B><P>
Add the following function:<P>
<P>
<A REL=DEFINITION HREF="../Body/f_map_in.htm#map-into"><B>MAP-INTO</B></A> result-sequence function &amp;rest sequences [Function]<P>
<P>
Destructively modifies the result-sequence to contain the results of<P>
applying function to each element in the argument sequences in turn.<P>
Returns result-sequence.<P>
<P>
The arguments result-sequence and each element of sequences can each be<P>
either a list or a vector (one-dimensional array). Note that <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> is<P>
considered to be a sequence, of length zero. If result-sequence and<P>
each element of sequences are not all the same length, the iteration<P>
terminates when the shortest sequence is exhausted. If result-sequence<P>
is a vector with a <A REL=DEFINITION HREF="../Body/f_fill_p.htm#fill-pointer"><B>fill-pointer</B></A>, the <A REL=DEFINITION HREF="../Body/f_fill_p.htm#fill-pointer"><B>fill-pointer</B></A> is ignored when<P>
deciding how many iterations to perform, and afterwards the<P>
<A REL=DEFINITION HREF="../Body/f_fill_p.htm#fill-pointer"><B>fill-pointer</B></A> is set to the number of times function was applied.<P>
<P>
If result-sequence is longer than the shortest element of sequences,<P>
extra elements at the end of result-sequence are left unchanged.<P>
<P>
<A REL=DEFINITION HREF="../Body/f_map_in.htm#map-into"><B>MAP-INTO</B></A> differs from <A REL=DEFINITION HREF="../Body/f_map.htm#map"><B>MAP</B></A> in that it modifies an existing sequence<P>
rather than creating a new one. In addition, <A REL=DEFINITION HREF="../Body/f_map_in.htm#map-into"><B>MAP-INTO</B></A> can be called<P>
with only two arguments, while <A REL=DEFINITION HREF="../Body/f_map.htm#map"><B>MAP</B></A> requires at least three arguments.<P>
If result-sequence is <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, <A REL=DEFINITION HREF="../Body/f_map_in.htm#map-into"><B>MAP-INTO</B></A> immediately returns <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, since<P>
<A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> is a sequence of length zero.<P>
<P>
If BIT-ARRAY-FUNCTIONS:NO-NEW-FUNCTIONS passes, then <A REL=DEFINITION HREF="../Body/f_map_in.htm#map-into"><B>MAP-INTO</B></A> will<P>
allow result-sequence and each element of sequences to be mappables<P>
all of the same rank.<P>
<P>
The function must take at least as many arguments as there are<P>
sequences provided.<P>
<P>
If function has side effects, it can count on being called first on all<P>
of the elements with index 0, then on all of those numbered 1, and so<P>
on.<P>
<P>
<B>Examples:<P>
</B><P>
(<A REL=DEFINITION HREF="../Body/f_map_in.htm#map-into"><B>map-into</B></A> x #'+ x y)<P>
(<A REL=DEFINITION HREF="../Body/f_map_in.htm#map-into"><B>map-into</B></A> q #'<A REL=DEFINITION HREF="../Body/a_cons.htm#cons"><B>cons</B></A> keys vals)<P>
(<A REL=DEFINITION HREF="../Body/f_map_in.htm#map-into"><B>map-into</B></A> syms #'<A REL=DEFINITION HREF="../Body/f_gensym.htm#gensym"><B>gensym</B></A>)<P>
<P>
<B>Rationale:<P>
</B><P>
<A REL=DEFINITION HREF="../Body/f_map_in.htm#map-into"><B>MAP-INTO</B></A> is a simple way to express reuse of storage that is<P>
stylistically consistent with the rest of Common Lisp.<P>
<P>
<B>Current practice:<P>
</B><P>
Symbolics Genera 7.2 implements the proposal.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
Small.<P>
<P>
<B>Cost to Users:<P>
</B><P>
None.<P>
<P>
<B>Cost of non-adoption:<P>
</B><P>
Small.<P>
<P>
<B>Performance impact:<P>
</B><P>
None.<P>
<P>
<B>Benefits:<P>
</B><P>
More expressive language.<P>
<P>
<B>Esthetics:<P>
</B><P>
User programs won't have to write the above examples as<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_loop.htm#loop"><B>loop</B></A> for xx on x <A REL=DEFINITION HREF="../Body/a_and.htm#and"><B>and</B></A> yy in y <A REL=DEFINITION HREF="../Body/m_do_do.htm#do"><B>do</B></A><P>
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>setf</B></A> (<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>car</B></A> xx) (+ (<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>car</B></A> xx) yy)))<P>
<P>
or something else about equally horrible.<P>
<P>
<B>Discussion:<P>
</B><P>
None.<P>
</PRE>
<HR>
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
</BODY>
</HTML>