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

181 lines
11 KiB
HTML
Raw 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 SETF-MULTIPLE-STORE-VARIABLES 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/iss308_w.htm">
<LINK REL=UP HREF="../Issues/iss309.htm">
<LINK REL=NEXT HREF="../Issues/iss310_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/iss308_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss309.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss310_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue SETF-MULTIPLE-STORE-VARIABLES Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss309.htm">SETF-MULTIPLE-STORE-VARIABLES</A><P>
<P>
<B>References:</B> CLtL, pp.93-107<P>
Lisp Pointers, v2n2, pp.27-41<P>
<P>
<B>Category:</B> ADDITION<P>
<P>
<B>Edit history:</B> Version 1, 5-Dec-88, Pavel<P>
Version 2, 22-Mar-89, Moon, simplify, update from discussion<P>
<P>
<B>Problem description:<P>
</B> <P>
The description of GET-SETF-METHOD-MULTIPLE-VALUE on page 107 of CLtL<P>
states that there are no cases in Common Lisp that allow multiple values<P>
to be stored into a generalized variable. This is seen by some as an<P>
arbitrary decision in light of the fact that a very reasonable semantics<P>
exists for multiple values being assigned by several Common Lisp macros,<P>
including <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A>. The rationale on page 103 of CLtL suggests that this<P>
decision might be changed in the future.<P>
<P>
<B>Proposal (SETF-MULTIPLE-STORE-VARIABLES:ALLOW):<P>
</B><P>
Extend the semantics of the macros <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A>, <A REL=DEFINITION HREF="../Body/m_setf_.htm#psetf"><B>PSETF</B></A>, <A REL=DEFINITION HREF="../Body/m_shiftf.htm#shiftf"><B>SHIFTF</B></A>, <A REL=DEFINITION HREF="../Body/m_rotate.htm#rotatef"><B>ROTATEF</B></A>, and<P>
<A REL=DEFINITION HREF="../Body/m_assert.htm#assert"><B>ASSERT</B></A> to allow &quot;places&quot; whose <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> methods have more than one &quot;store<P>
variable&quot;. In such cases, the macros accept as many values from the<P>
newvalue form as there are store variables. As usual, extra values<P>
are ignored and missing values default to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>.<P>
<P>
Extend the long form of <A REL=DEFINITION HREF="../Body/m_defset.htm#defsetf"><B>DEFSETF</B></A> to allow the specification of more<P>
than one &quot;store variable&quot;, with the obvious semantics.<P>
<P>
Clarify that GET-SETF-METHOD signals an error if there would be more<P>
than one store-variable.<P>
<P>
<B>Test Cases/Examples:<P>
</B> <P>
(<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>defstruct</B></A> region width height)<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>defun</B></A> region-size (region)<P>
(<A REL=DEFINITION HREF="../Body/a_values.htm#values"><B>values</B></A><P>
(region-width region)<P>
(region-height region)))<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_defset.htm#defsetf"><B>defsetf</B></A> region-size (region) (width height)<P>
`(<A REL=DEFINITION HREF="../Body/a_values.htm#values"><B>values</B></A><P>
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>setf</B></A> (region-width ,region) ,width)<P>
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>setf</B></A> (region-height ,region) ,height)))<P>
<P>
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>setf</B></A> my-reg (make-region :width 10 :height 20))<P>
=&gt; #S(REGION :WIDTH 10 :HEIGHT 20)<P>
<P>
(region-size my-reg)<P>
=&gt; 10<P>
20<P>
<P>
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>setf</B></A> (region-size my-reg) (<A REL=DEFINITION HREF="../Body/a_values.htm#values"><B>values</B></A> 30 40))<P>
=&gt; 30<P>
40<P>
<P>
(region-size my-reg)<P>
=&gt; 30<P>
40 <P>
<P>
<B>Rationale:<P>
</B> <P>
This change removes an artificial restriction on the semantics of<P>
several Common Lisp macros, allowing a broader set of contexts in<P>
which generalized variables can be used. For example, it is not<P>
difficult to write a reasonable <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> for the <A REL=DEFINITION HREF="../Body/a_values.htm#values"><B>VALUES</B></A> function,<P>
yielding a powerful MULTIPLE-VALUE-SETF form:<P>
<P>
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>setf</B></A> (<A REL=DEFINITION HREF="../Body/a_values.htm#values"><B>values</B></A> (<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>car</B></A> a) (<A REL=DEFINITION HREF="../Body/f_gethas.htm#gethash"><B>gethash</B></A> b 'c) (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>aref</B></A> d 13))<P>
(some-hairy-computation))<P>
<P>
In the language as currently defined, this example would have to be<P>
written:<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_multip.htm#multiple-value-bind"><B>multiple-value-bind</B></A> (x y z)<P>
(some-hairy-computation)<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> a) x<P>
(<A REL=DEFINITION HREF="../Body/f_gethas.htm#gethash"><B>gethash</B></A> b 'c) y<P>
(<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>aref</B></A> d 13) z))<P>
<P>
Many other (perhaps more compelling) examples of generalized variables<P>
holding more than one value can easily be imagined. Their use,<P>
however, is severely discouraged by Common Lisp as defined in CLtL,<P>
since none of the built-in macros will accept them.<P>
<P>
The clarification of GET-SETF-METHOD makes explicit what is implied<P>
by CLtL (CLtL uses the word &quot;guarantee&quot;, whose relationship to<P>
signalling of errors is unclear).<P>
<P>
<B>Current practice:<P>
</B><P>
I do not know of any implementations that allow all of this extension.<P>
Xerox Lisp does not signal an error, but this is probably due to a bug<P>
in GET-SETF-METHOD. Lucid signals an error in GET-SETF-METHOD.<P>
Symbolics Genera supports the proposal in <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> and <A REL=DEFINITION HREF="../Body/m_setf_.htm#psetf"><B>PSETF</B></A>, but not in<P>
<A REL=DEFINITION HREF="../Body/m_shiftf.htm#shiftf"><B>SHIFTF</B></A>, <A REL=DEFINITION HREF="../Body/m_rotate.htm#rotatef"><B>ROTATEF</B></A>, and <A REL=DEFINITION HREF="../Body/m_assert.htm#assert"><B>ASSERT</B></A>.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
A relatively minor fix to each of the affected macros suffices. For<P>
example, to fix <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> itself, one need only call<P>
GET-SETF-METHOD-MULTIPLE-VALUE instead of GET-SETF-METHOD and emit a<P>
<A REL=DEFINITION HREF="../Body/m_multip.htm#multiple-value-bind"><B>MULTIPLE-VALUE-BIND</B></A> instead of a <A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>LET</B></A> for binding the store variables.<P>
<P>
<B>Cost to Users:<P>
</B><P>
This is an upward-compatible change; no user code must change.<P>
<P>
<B>Cost of non-adoption:<P>
</B><P>
Yet another non-uniformity in the language, yet another piece of<P>
mechanism without a clear use (GET-SETF-METHOD-MULTIPLE-VALUE).<P>
<P>
<B>Benefits:<P>
</B><P>
Wider applicability of a reasonably nice abstraction, the removal of<P>
an artificial prohibition.<P>
<P>
<B>Aesthetics:<P>
</B><P>
People may disagree about whether this is a simplification or not. I<P>
am firmly on the side that believes that such removal of<P>
non-uniformities is a simplifying force in the language.<P>
<P>
<B>Discussion:<P>
</B><P>
Pavel supports this proposal.<P>
<P>
Moon supports this proposal except he is not sure about the<P>
inclusion of <A REL=DEFINITION HREF="../Body/m_assert.htm#assert"><B>ASSERT</B></A>.<P>
<P>
GSB suggests that this is a clarification rather than an addition,<P>
because the lack of any predefined setf-methods that use multiple<P>
store variables should not mean that <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A>, etc. should not work with<P>
such a setf-method if the user defined one. The problem is that CLtL<P>
examples such as the ones for <A REL=DEFINITION HREF="../Body/m_shiftf.htm#shiftf"><B>SHIFTF</B></A> on p.98 and the simplified<P>
definition for <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> on p.107 contradict this proposal, and might have<P>
been taken as specifications, rather than simplified examples, by<P>
some readers.<P>
<P>
Predefined <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> methods for such functions as <A REL=DEFINITION HREF="../Body/a_values.htm#values"><B>VALUES</B></A>, <A REL=DEFINITION HREF="../Body/a_cons.htm#cons"><B>CONS</B></A>, and <A REL=DEFINITION HREF="../Body/a_vector.htm#vector"><B>VECTOR</B></A><P>
could have been proposed, but we refrained. This proposal is necessary<P>
to allow the user to write such methods for himself, but if this<P>
proposal is adopted those setf-methods are very easy to write in<P>
a portable fashion.<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>