147 lines
10 KiB
HTML
147 lines
10 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 GET-SETF-METHOD-ENVIRONMENT 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/iss184_w.htm">
|
|
<LINK REL=UP HREF="../Issues/iss185.htm">
|
|
<LINK REL=NEXT HREF="../Issues/iss186_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/iss184_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss185.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss186_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2>Issue GET-SETF-METHOD-ENVIRONMENT Writeup</H2>
|
|
|
|
<PRE><B>Issue:</B> <A HREF="iss185.htm">GET-SETF-METHOD-ENVIRONMENT</A><P>
|
|
<B>References:</B> GET-SETF-METHOD (CLtL p 187)<P>
|
|
<B>Category:</B> Change<P>
|
|
<B>Edit History:</B> Version 1 9-Jan-87, Version 1 by Masinter <P>
|
|
(no version) 7-Apr-87, merged with ENVIRONMENT-ARGUMENTS<P>
|
|
Version 2 29-May-87, extracted again <P>
|
|
Version 3 5-Jun-87, by Masinter<P>
|
|
Version 4 11-Jun-87, for release<P>
|
|
Version 5 13-Jul-87, by Masinter<P>
|
|
<P>
|
|
<B>Problem Description:<P>
|
|
</B><P>
|
|
If a macro that performs similar processing to <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> uses GET-SETF-METHOD,<P>
|
|
and that macro occurs within a <A REL=DEFINITION HREF="../Body/s_flet_.htm#macrolet"><B>MACROLET</B></A>, the expansion will not see the<P>
|
|
<A REL=DEFINITION HREF="../Body/s_flet_.htm#macrolet"><B>MACROLET</B></A> definition, e.g.,<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_defmac.htm#defmacro"><B>defmacro</B></A> special-incf ... (get-setf-method ...) ...)<P>
|
|
<P>
|
|
then <P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_flet_.htm#macrolet"><B>macrolet</B></A> ((test (x) `(<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>car</B></A> ,x)))<P>
|
|
(special-incf (test z)))<P>
|
|
<P>
|
|
would not "see" the test definition.<P>
|
|
<P>
|
|
<B>Proposal (GET-SETF-METHOD-ENVIRONMENT:ADD-ARG):<P>
|
|
</B><P>
|
|
Add an optional environment argument to GET-SETF-METHOD and<P>
|
|
GET-SETF-METHOD-MULTIPLE-VALUE. If the argument is not supplied, it<P>
|
|
defaults to the null lexical environment. <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> can also be passed explicitly<P>
|
|
to denote the null lexical environment.<P>
|
|
<P>
|
|
Allow <A REL=DEFINITION HREF="../Body/03_dd.htm#AMenvironment"><B>&ENVIRONMENT</B></A> variable to appear in the lambda-list subform of a<P>
|
|
DEFINE-SETF-METHOD form, as with a <A REL=DEFINITION HREF="../Body/m_defmac.htm#defmacro"><B>DEFMACRO</B></A>.<P>
|
|
<P>
|
|
Note that macros defined with <A REL=DEFINITION HREF="../Body/m_defi_2.htm#define-modify-macro"><B>DEFINE-MODIFY-MACRO</B></A> correctly pass the<P>
|
|
environment to GET-SETF-METHOD.<P>
|
|
<P>
|
|
Clarify that, within the scope of a <A REL=DEFINITION HREF="../Body/s_flet_.htm#macrolet"><B>MACROLET</B></A>, <A REL=DEFINITION HREF="../Body/s_flet_.htm#flet"><B>FLET</B></A> and <A REL=DEFINITION HREF="../Body/s_flet_.htm#labels"><B>LABELS</B></A>, global <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A><P>
|
|
definitions of the name defined by the <A REL=DEFINITION HREF="../Body/s_flet_.htm#macrolet"><B>MACROLET</B></A>, <A REL=DEFINITION HREF="../Body/s_flet_.htm#flet"><B>FLET</B></A> or <A REL=DEFINITION HREF="../Body/s_flet_.htm#labels"><B>LABELS</B></A> do not<P>
|
|
apply. A <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> applies only when the global function binding of the<P>
|
|
name is lexically visible. All of the built in macros of Common Lisp<P>
|
|
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A>, <A REL=DEFINITION HREF="../Body/m_incf_.htm#incf"><B>INCF</B></A>, <A REL=DEFINITION HREF="../Body/m_incf_.htm#decf"><B>DECF</B></A>, <A REL=DEFINITION HREF="../Body/m_pop.htm#pop"><B>POP</B></A>, <A REL=DEFINITION HREF="../Body/m_rotate.htm#rotatef"><B>ROTATEF</B></A>, etc.) which modify location specifications<P>
|
|
obey this convention.<P>
|
|
<P>
|
|
<B>Test Case:<P>
|
|
</B><P>
|
|
;;; This macro is like <A REL=DEFINITION HREF="../Body/m_pop.htm#pop"><B>POP</B></A> <P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_defmac.htm#defmacro"><B>defmacro</B></A> xpop (place <A REL=DEFINITION HREF="../Body/03_dd.htm#AMenvironment"><B>&environment</B></A> env)<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_multip.htm#multiple-value-bind"><B>multiple-value-bind</B></A> (dummies vals new setter getter)<P>
|
|
(get-setf-method place env)<P>
|
|
`(<A REL=DEFINITION HREF="../Body/s_let_l.htm#letST"><B>let*</B></A> (,@(<A REL=DEFINITION HREF="../Body/f_mapc_.htm#mapcar"><B>mapcar</B></A> #'<A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>list</B></A> dummies vals) (,(<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>car</B></A> new) ,getter))<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_prog1c.htm#prog1"><B>prog1</B></A> (<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>car</B></A> ,(<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>car</B></A> new))<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_setq.htm#setq"><B>setq</B></A> ,(<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>car</B></A> new) (<A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>cdr</B></A> ,(<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>car</B></A> new)))<P>
|
|
,setter)))))<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_defset.htm#defsetf"><B>defsetf</B></A> frob (x) (value) <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> ,x) ,value))<P>
|
|
<P>
|
|
;;; The following will modify (<A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>cdr</B></A> z) and not (<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>car</B></A> z)<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_flet_.htm#macrolet"><B>macrolet</B></A> ((frob (x) `(<A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>cdr</B></A> ,x)))<P>
|
|
(xpop (frob z)))<P>
|
|
<P>
|
|
;;; The following is an error; an error may be signaled at macro expansion<P>
|
|
time<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_flet_.htm#flet"><B>flet</B></A> ((frob (x) (<A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>cdr</B></A> x))<P>
|
|
(xpop (frob z)))<P>
|
|
<P>
|
|
<P>
|
|
<B>Rationale:<P>
|
|
</B><P>
|
|
This was an omission in the original definition of CLtL.<P>
|
|
<P>
|
|
<B>Current Practice:<P>
|
|
</B><P>
|
|
Many Common Lisp implementations already have this extension, although some<P>
|
|
do not. One implementation has extended GET-SETF-METHOD to take an optional<P>
|
|
argument which is incompatible with this use.<P>
|
|
<P>
|
|
<B>Cost to implementors:<P>
|
|
</B><P>
|
|
Some implementations will have to add this feature, although it is not a<P>
|
|
major change.<P>
|
|
<P>
|
|
<B>Cost to users:<P>
|
|
</B><P>
|
|
This is generally an upward compatible change. In implementations which did<P>
|
|
not already take into account the lexical environment for <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A>'d forms<P>
|
|
might start working differently if the internal implementation of <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> is<P>
|
|
changed. The likelihood of this affecting a user's program is very small.<P>
|
|
<P>
|
|
<B>Benefits:<P>
|
|
</B><P>
|
|
This change improves portability and the ability to use <A REL=DEFINITION HREF="../Body/s_flet_.htm#macrolet"><B>MACROLET</B></A>, <A REL=DEFINITION HREF="../Body/s_flet_.htm#flet"><B>FLET</B></A> and<P>
|
|
<A REL=DEFINITION HREF="../Body/s_flet_.htm#labels"><B>LABELS</B></A> in portable code which might also have <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> forms.<P>
|
|
<P>
|
|
<B>Aesthetics:<P>
|
|
</B><P>
|
|
<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> methods cannot work correctly within lexically defined function<P>
|
|
symbols without this change. This change makes the language more consistent<P>
|
|
and correct. <P>
|
|
<P>
|
|
<B>Discussion:<P>
|
|
</B><P>
|
|
The cleanup committee generally supports this change.<P>
|
|
<P>
|
|
A number of additional changes for rationally dealing with lexical<P>
|
|
environments as first <A REL=DEFINITION HREF="../Body/t_class.htm#class"><B>class</B></A> objects, including a more general set of<P>
|
|
accessors and constructors for lexical environments is required for many<P>
|
|
language extensions (e.g., a portable version of the proposed Common Lisp<P>
|
|
Object System) and should be addressed by a future proposal. For a while,<P>
|
|
the cleanup committee attempted to deal with these issues together, but<P>
|
|
decided to separate them out into their component parts. This issue is the<P>
|
|
simplest.<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>
|