1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Issues/iss298_w.htm
2024-04-01 10:24:07 +02:00

127 lines
8.8 KiB
HTML

<!-- 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 RESULT-LISTS-SHARED 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/iss297_w.htm">
<LINK REL=UP HREF="../Issues/iss298.htm">
<LINK REL=NEXT HREF="../Issues/iss299_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/iss297_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss298.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss299_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue RESULT-LISTS-SHARED Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss298.htm">RESULT-LISTS-SHARED</A><P>
<B>Forum:</B> Editorial<P>
<B>References:</B> <A REL=DEFINITION HREF="../Body/f_dir.htm#directory"><B>DIRECTORY</B></A> (p427), <A REL=DEFINITION HREF="../Body/f_list_a.htm#list-all-packages"><B>LIST-ALL-PACKAGES</B></A> (p184)<P>
<B>Category:</B> CLARIFICATION<P>
<B>Edit history:</B> 02-Mar-91, Version 1 by Pitman<P>
15-Mar-91, Version 2 by Pitman (repair current practice)<P>
<B>Status:</B> For X3J13 consideration<P>
<P>
<B>Problem Description:<P>
</B><P>
CLtL does not specify whether the list returned by each of these<P>
functions is freshly-consed each time, or whether it must be treated<P>
as immutable: <A REL=DEFINITION HREF="../Body/f_list_a.htm#list-all-packages"><B>LIST-ALL-PACKAGES</B></A>, <A REL=DEFINITION HREF="../Body/f_dir.htm#directory"><B>DIRECTORY</B></A>.<P>
<P>
<B>Proposal (RESULT-LISTS-SHARED:SPECIFY):<P>
</B><P>
Specify that the lists returned by <A REL=DEFINITION HREF="../Body/f_list_a.htm#list-all-packages"><B>LIST-ALL-PACKAGES</B></A> and <A REL=DEFINITION HREF="../Body/f_dir.htm#directory"><B>DIRECTORY</B></A> are<P>
freshly consed on every call. The list resulting from calls to these<P>
functions may therefore be freely modified by the caller.<P>
<P>
<B>Example:<P>
</B><P>
;Example of recycling list <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> from <A REL=DEFINITION HREF="../Body/f_list_a.htm#list-all-packages"><B>LIST-ALL-PACKAGES</B></A><P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>DEFUN</B></A> ALIST-ALL-PACKAGES ()<P>
(<A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>LET</B></A> ((P (<A REL=DEFINITION HREF="../Body/f_list_a.htm#list-all-packages"><B>LIST-ALL-PACKAGES</B></A>)))<P>
(<A REL=DEFINITION HREF="../Body/m_do_do.htm#do"><B>DO</B></A> ((L P (<A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>CDR</B></A> L)))<P>
((<A REL=DEFINITION HREF="../Body/a_null.htm#null"><B>NULL</B></A> L) P)<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> L)<P>
(<A REL=DEFINITION HREF="../Body/f_list_.htm#listST"><B>LIST*</B></A> (<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>CAR</B></A> L)<P>
(<A REL=DEFINITION HREF="../Body/f_pkg_na.htm#package-name"><B>PACKAGE-NAME</B></A> (<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>CAR</B></A> L))<P>
(<A REL=DEFINITION HREF="../Body/f_pkg_ni.htm#package-nicknames"><B>PACKAGE-NICKNAMES</B></A> (<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>CAR</B></A> L)))))))<P>
<P>
;Example of recycling list <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> from <A REL=DEFINITION HREF="../Body/f_dir.htm#directory"><B>DIRECTORY</B></A><P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>DEFUN</B></A> FULL-DIRECTORY (SPEC)<P>
(<A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>LET</B></A> ((D (<A REL=DEFINITION HREF="../Body/f_dir.htm#directory"><B>DIRECTORY</B></A> SPEC)))<P>
(<A REL=DEFINITION HREF="../Body/m_do_do.htm#do"><B>DO</B></A> ((L D (<A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>CDR</B></A> L)))<P>
((<A REL=DEFINITION HREF="../Body/a_null.htm#null"><B>NULL</B></A> L) D)<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> L)<P>
(<A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>LIST</B></A> (<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>CAR</B></A> L)<P>
:AUTHOR (<A REL=DEFINITION HREF="../Body/f_file_a.htm#file-author"><B>FILE-AUTHOR</B></A> (<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>CAR</B></A> L))<P>
:WRITE-DATE (<A REL=DEFINITION HREF="../Body/f_file_w.htm#file-write-date"><B>FILE-WRITE-DATE</B></A> (<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>CAR</B></A> L))<P>
:LENGTH (<A REL=DEFINITION HREF="../Body/m_ignore.htm#ignore-errors"><B>IGNORE-ERRORS</B></A><P>
(<A REL=DEFINITION HREF="../Body/m_w_open.htm#with-open-file"><B>WITH-OPEN-FILE</B></A> (S (<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>CAR</B></A> L))<P>
(<A REL=DEFINITION HREF="../Body/f_file_l.htm#file-length"><B>FILE-LENGTH</B></A> S))))))))<P>
<P>
<B>Rationale:<P>
</B><P>
In most implementations, packages are stored in a hash table for<P>
faster access by the reader, so the list returned by <A REL=DEFINITION HREF="../Body/f_list_a.htm#list-all-packages"><B>LIST-ALL-PACKAGES</B></A><P>
is probably freshly consed already. Also, <A REL=DEFINITION HREF="../Body/f_list_a.htm#list-all-packages"><B>LIST-ALL-PACKAGES</B></A> is<P>
probably called sufficiently seldom that there is no serious<P>
efficiency issue here.<P>
<P>
In most implementations, information about the file system is external<P>
to Lisp and must be freshly computed each time a directory listing is<P>
done anyway. Better not to force the caller to do a <A REL=DEFINITION HREF="../Body/f_cp_lis.htm#copy-list"><B>COPY-LIST</B></A> on a<P>
call when the list can easily be guaranteed to be fresh to begin with.<P>
<P>
Even in situations where it was possible to return a<P>
non-freshly-consed list, this might put internal data structures of<P>
the implementation at risk for no really good efficiency reason.<P>
<P>
<B>Current Practice:<P>
</B><P>
Symbolics Genera freshly conses the list returned by <A REL=DEFINITION HREF="../Body/f_dir.htm#directory"><B>DIRECTORY</B></A>.<P>
Symbolics Genera does not freshly cons the list returned by <A REL=DEFINITION HREF="../Body/f_list_a.htm#list-all-packages"><B>LIST-ALL-PACKAGES</B></A>.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
Very small.<P>
<P>
<B>Cost to Users:<P>
</B><P>
None.<P>
<P>
<B>Cost of Non-Adoption:<P>
</B><P>
Users wouldn't know what to expect and would be forced to do a<P>
<A REL=DEFINITION HREF="../Body/f_cp_lis.htm#copy-list"><B>COPY-LIST</B></A> just to be sure when they planned to modify the result. If<P>
they forgot, and the implementation decided to return a<P>
non-freshly-consed list, an attempt to modify that list might<P>
compromise the integrity of the running Lisp.<P>
<P>
<B>Benefits:<P>
</B><P>
Clearer specfication<P>
<P>
<B>Aesthetics:<P>
</B><P>
Negligible effect.<P>
<P>
<B>Discussion:<P>
</B><P>
Pitman supports this proposal. (He's more than once wanted to modify<P>
the result list of <A REL=DEFINITION HREF="../Body/f_dir.htm#directory"><B>DIRECTORY</B></A> and had to do a gratuitous <A REL=DEFINITION HREF="../Body/f_cp_lis.htm#copy-list"><B>COPY-LIST</B></A> just<P>
to be safe.)<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>