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

119 lines
6.5 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 REDUCE-ARGUMENT-EXTRACTION 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/iss291_w.htm">
<LINK REL=UP HREF="../Issues/iss292.htm">
<LINK REL=NEXT HREF="../Issues/iss293_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/iss291_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss292.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss293_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue REDUCE-ARGUMENT-EXTRACTION Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss292.htm">REDUCE-ARGUMENT-EXTRACTION</A><P>
<B>References:</B> <A REL=DEFINITION HREF="../Body/f_reduce.htm#reduce"><B>REDUCE</B></A> (pp. 251-252), :KEY arguments (p. 246), <P>
the astronaut <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> (pp. 312-313)<P>
<B>Category:</B> ADDITION<P>
<B>Edit history:</B> Version 1 by Pierson 5-Dec-87<P>
Version 2 by Pierson 30-Dec-87<P>
Version 3 by Masinter 13-Feb-88<P>
<P>
<B>Problem description:<P>
</B><P>
<A REL=DEFINITION HREF="../Body/f_reduce.htm#reduce"><B>REDUCE</B></A> is the only one of the Common Lisp functions that modify or<P>
search lists and sequences which does not accept a :KEY argument.<P>
This complicates many uses of <A REL=DEFINITION HREF="../Body/f_reduce.htm#reduce"><B>REDUCE</B></A>.<P>
<P>
<B>Proposal (REDUCE-ARGUMENT-EXTRACTION:KEY):<P>
</B><P>
Change the definition of <A REL=DEFINITION HREF="../Body/f_reduce.htm#reduce"><B>REDUCE</B></A> to take a :KEY keyword described as<P>
follows: <P>
<P>
If a :KEY argument is supplied, its value must be a function of one<P>
argument which will be used to extract the values to reduce. The :KEY<P>
function will be applied exactly once to each element of the sequence<P>
in the order implied by the reduction order but not to the value of<P>
the :INITIAL-VALUE argument, if any.<P>
<P>
<B>Example:<P>
</B><P>
Using <A REL=DEFINITION HREF="../Body/f_reduce.htm#reduce"><B>REDUCE</B></A> to obtain the total of the ages of the possibly empty<P>
sequence of astronauts ASTROS, would currently require:<P>
<P>
(<A REL=DEFINITION HREF="../Body/f_reduce.htm#reduce"><B>REDUCE</B></A> #'+ (<A REL=DEFINITION HREF="../Body/f_map.htm#map"><B>MAP</B></A> '<A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>LIST</B></A> #'PERSON-AGE ASTROS))<P>
<P>
If this proposal is adopted, the same result could be obtained without<P>
creating a new list by: <P>
<P>
(<A REL=DEFINITION HREF="../Body/f_reduce.htm#reduce"><B>REDUCE</B></A> #'+ ASTROS :KEY #'PERSON-AGE)<P>
<P>
<B>Rationale:<P>
</B><P>
This proposal makes many common situations where <A REL=DEFINITION HREF="../Body/f_reduce.htm#reduce"><B>REDUCE</B></A> would be useful<P>
much less cumbersome.<P>
<P>
<B>Current practice:<P>
</B><P>
We know of no implementation which currently supports this feature.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
This will <A REL=DEFINITION HREF="../Body/f_provid.htm#require"><B>require</B></A> most implementations to make a trivial modification<P>
to <A REL=DEFINITION HREF="../Body/f_reduce.htm#reduce"><B>REDUCE</B></A>. Implementations which wish to use this as an opportunity to<P>
further optimize compiled calls to <A REL=DEFINITION HREF="../Body/f_reduce.htm#reduce"><B>REDUCE</B></A> will have to undertake more<P>
work (which would be much more difficult today).<P>
<P>
<B>Cost to Users:<P>
</B><P>
None, this is an upward compatible extension.<P>
<P>
<B>Cost of non-Adoption:<P>
</B><P>
<A REL=DEFINITION HREF="../Body/f_reduce.htm#reduce"><B>REDUCE</B></A> will continue to be more difficult to use than other sequence<P>
functions on sequences of complex objects.<P>
<P>
<B>Benefits:<P>
</B><P>
<A REL=DEFINITION HREF="../Body/f_reduce.htm#reduce"><B>REDUCE</B></A> will become easier to use on sequences of complex objects. It<P>
will be easier for compilers to convert some calls to <A REL=DEFINITION HREF="../Body/f_reduce.htm#reduce"><B>REDUCE</B></A> into<P>
efficient loops.<P>
<P>
<B>Aesthetics:<P>
</B><P>
Slightly damaged in one way. All :KEY arguments are currently defined<P>
to be used for predicates, this proposal will implicitly broaden :KEY<P>
to support general extraction for any purpose.<P>
<P>
Slightly improved in another way. Many common situations where <A REL=DEFINITION HREF="../Body/f_reduce.htm#reduce"><B>REDUCE</B></A><P>
could be used would be easier to write and easier to later read.<P>
<P>
<B>Discussion:<P>
</B><P>
Several members of the committee feel that the increased functionality<P>
outweighs the damage to the definition of :KEY. No one has objected<P>
to this change in the recent round of discussions.<P>
<P>
There is some controversy over whether the &quot;definition&quot; of :KEY<P>
arguments on page 246 of CLtL really constitutes a definition or just<P>
an &quot;unwritten rule&quot;.<P>
<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>