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

139 lines
8.2 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 MAPPING-DESTRUCTIVE-INTERACTION 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/iss239_w.htm">
<LINK REL=UP HREF="../Issues/iss240.htm">
<LINK REL=NEXT HREF="../Issues/iss241_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/iss239_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss240.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss241_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue MAPPING-DESTRUCTIVE-INTERACTION Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss240.htm">MAPPING-DESTRUCTIVE-INTERACTION</A><P>
<B>References:</B> <A REL=DEFINITION HREF="../Body/f_mapc_.htm#mapcar"><B>MAPCAR</B></A>, <A REL=DEFINITION HREF="../Body/f_mapc_.htm#maplist"><B>MAPLIST</B></A>, ... (p128);<P>
<A REL=DEFINITION HREF="../Body/m_dolist.htm#dolist"><B>DOLIST</B></A> (p126); <A REL=DEFINITION HREF="../Body/f_maphas.htm#maphash"><B>MAPHASH</B></A> (p285); <P>
<A REL=DEFINITION HREF="../Body/m_do_sym.htm#do-symbols"><B>DO-SYMBOLS</B></A>, <A REL=DEFINITION HREF="../Body/m_do_sym.htm#do-external-symbols"><B>DO-EXTERNAL-SYMBOLS</B></A>, <A REL=DEFINITION HREF="../Body/m_do_sym.htm#do-all-symbols"><B>DO-ALL-SYMBOLS</B></A> (pp187-188);<P>
All functions using :TEST <P>
Related-Issues: <A HREF="iss293.htm">REMF-DESTRUCTION-UNSPECIFIED</A>.<P>
<B>Category:</B> CLARIFICATION<P>
<B>Edit history:</B> 07-Mar-88, Version 1 by Pitman<P>
09-Jun-88, Version 2 by Pitman<P>
(merge Moon's comments and update current practice)<P>
<P>
<B>Problem Description:<P>
</B><P>
The interaction of mapping functions and <A REL=DEFINITION HREF="../Body/m_dolist.htm#dolist"><B>DOLIST</B></A> with destructive<P>
operations on the list being operated on is unclear. For example,<P>
if you destructively modify some tail of a list being mapped down,<P>
does that affect the mapping process?<P>
<P>
<B>Proposal (MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE):<P>
</B><P>
Clarify that it in general is an error (the effect is not defined<P>
but in general no error will be signalled) for code executed during a<P>
&quot;structure traversing&quot; operation to destructively modify the<P>
<A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> in a way that might affect the ongoing traversal operation.<P>
<P>
For list traversal operations, this means that the <A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>cdr</B></A> chain of the<P>
list may not be destructively modified.<P>
<P>
For array traversal operations, the array may not be adjusted and<P>
its <A REL=DEFINITION HREF="../Body/f_fill_p.htm#fill-pointer"><B>fill-pointer</B></A>, if any, may not be changed.<P>
<P>
For hash tables, new elements may not be added or deleted EXCEPT<P>
that the element corresponding to the current hash key may be<P>
changed or removed.<P>
<P>
For packages, new symbols may not be interned in or uninterned from<P>
the package being traversed or any package that it uses EXCEPT that<P>
the current symbol may be uninterned from the package being traversed<P>
in a <A REL=DEFINITION HREF="../Body/m_do_sym.htm#do-symbols"><B>DO-SYMBOLS</B></A>.<P>
<P>
Note: This proposal is intended to clarify restrictions on user code<P>
for use with <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> manipulators which are not inherently<P>
destructive. Other operators, such as <A REL=DEFINITION HREF="../Body/f_rm_dup.htm#delete-duplicates"><B>DELETE-DUPLICATES</B></A> or <A REL=DEFINITION HREF="../Body/f_revers.htm#nreverse"><B>NREVERSE</B></A>,<P>
may have much more complicated restrictions and are intentionally not<P>
treated by this proposal. See the issue <A HREF="iss293.htm">REMF-DESTRUCTION-UNSPECIFIED</A><P>
for more discussion of such issues.<P>
<P>
<B>Test Case:<P>
</B><P>
(<A REL=DEFINITION HREF="../Body/s_let_l.htm#letST"><B>LET*</B></A> ((L (<A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>LIST</B></A> 'A 'B 'C)) (LL L) (I 0))<P>
(<A REL=DEFINITION HREF="../Body/m_dolist.htm#dolist"><B>DOLIST</B></A> (FOO L)<P>
(<A REL=DEFINITION HREF="../Body/m_incf_.htm#incf"><B>INCF</B></A> I)<P>
(<A REL=DEFINITION HREF="../Body/s_if.htm#if"><B>IF</B></A> (<A REL=DEFINITION HREF="../Body/f_eq.htm#eq"><B>EQ</B></A> FOO 'B)<P>
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> (<A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>CDR</B></A> LL) <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>)<P>
(<A REL=DEFINITION HREF="../Body/m_pop.htm#pop"><B>POP</B></A> LL)))<P>
(<A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>LIST</B></A> I L)) might return (2 (A B)) or (3 (A B)), for example.<P>
<P>
<B>Rationale:<P>
</B><P>
This clarifies the status quo.<P>
<P>
Also, the likelihood that the user will want to destructively alter a<P>
<A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> while it is being traversed is low. The likelihood that such<P>
code would be readable and maintainable is also low. The likelihood <P>
that a compiler could do some interesting optimization if this point<P>
were not pinned down is high enough to be the overriding consideration<P>
in this case.<P>
<P>
<B>Current Practice:<P>
</B><P>
The implementation of <A REL=DEFINITION HREF="../Body/m_dolist.htm#dolist"><B>DOLIST</B></A> in Symbolics Genera, KCL, and PopLog Common Lisp<P>
returns (3 (A B)) for the test case.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
None. This simply makes the status quo explicit.<P>
<P>
<B>Cost to Users:<P>
</B><P>
Technically none. People who were mistakenly assuming that CLtL guaranteed<P>
things which it does not might be inclined to rewrite their code in a more<P>
portable way.<P>
<P>
<B>Cost of Non-Adoption:<P>
</B><P>
Users would be less informed.<P>
<P>
<B>Benefits:<P>
</B><P>
users would be more informed.<P>
<P>
<B>Aesthetics:<P>
</B><P>
Some might say it would be clearer to define this one way or the other, but<P>
advocates of both camps exist and their arguments are fairly symmetric.<P>
In any case, since this is a proposal to preserve the status quo, it has no<P>
major impact on aesthetics.<P>
<P>
<B>Discussion:<P>
</B><P>
This idea for this proposal was suggested by the Japanese community.<P>
<P>
Pitman drafted the formal proposal and supports the EXPLICITLY-VAGUE proposal.<P>
<P>
Moon generally supported version 1 of this proposal, but had some specific<P>
criticisms about weakness of the wording which this version is an attempt to fix.<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>