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

176 lines
12 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 DEFMETHOD-DECLARATION-SCOPE 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/iss106_w.htm">
<LINK REL=UP HREF="../Issues/iss107.htm">
<LINK REL=NEXT HREF="../Issues/iss108_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/iss106_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss107.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss108_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue DEFMETHOD-DECLARATION-SCOPE Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss107.htm">DEFMETHOD-DECLARATION-SCOPE</A><P>
<B>References:</B> <A REL=DEFINITION HREF="../Body/m_defmet.htm#defmethod"><B>DEFMETHOD</B></A>, <A REL=DEFINITION HREF="../Body/t_generi.htm#generic-function"><B>GENERIC-FUNCTION</B></A>, GENERIC-FLET, GENERIC-LABELS,<P>
<A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>CALL-NEXT-METHOD</B></A>, <A REL=DEFINITION HREF="../Body/f_next_m.htm#next-method-p"><B>NEXT-METHOD-P</B></A><P>
Related issues: <A HREF="iss092.htm">DECLARATION-SCOPE</A><P>
<A HREF="iss012.htm">ARGUMENT-MISMATCH-ERROR</A><P>
<A HREF="iss211.htm">LEXICAL-CONSTRUCT-GLOBAL-DEFINITION</A><P>
<A HREF="iss243.htm">METHOD-INITFORM</A><P>
<B>Category:</B> CLARIFICATION<P>
<B>Edit history:</B> v1, 27 Feb 91, Sandra Loosemore<P>
v2, 28 Feb 91, Sandra Loosemore<P>
<P>
<B>Problem description:<P>
</B><P>
The body of <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> definition in a <A REL=DEFINITION HREF="../Body/m_defmet.htm#defmethod"><B>DEFMETHOD</B></A>, <A REL=DEFINITION HREF="../Body/t_generi.htm#generic-function"><B>GENERIC-FUNCTION</B></A>,<P>
GENERIC-FLET, or GENERIC-LABELS form includes an implicit <A REL=DEFINITION HREF="../Body/s_flet_.htm#flet"><B>FLET</B></A> of <P>
<A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>CALL-NEXT-METHOD</B></A> and <A REL=DEFINITION HREF="../Body/f_next_m.htm#next-method-p"><B>NEXT-METHOD-P</B></A>. Can one put declarations at the <P>
head of the <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> body which apply to these bindings? Do &quot;free&quot; <P>
declarations (or declarations that don't apply to bindings) at the <P>
head of the <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> body apply to the definitions of these local <P>
functions? <P>
<P>
<P>
<B>Proposal (DEFMETHOD-DECLARATION-SCOPE:CORRESPONDS-TO-BINDINGS):<P>
</B><P>
Clarify that:<P>
<P>
(1) Declarations at the head of the <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> body that apply to the <P>
<A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A>'s <A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> variables are treated as &quot;bound&quot; declarations <P>
whose scope is the same as the corresponding bindings.<P>
<P>
(2) Declarations at the head of the <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> body that apply to the <P>
functional bindings of <A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>CALL-NEXT-METHOD</B></A> or <A REL=DEFINITION HREF="../Body/f_next_m.htm#next-method-p"><B>NEXT-METHOD-P</B></A> apply<P>
to references to those functions within the <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> body forms.<P>
Any outer bindings of these functions and declarations associated <P>
with those bindings are shadowed within the <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> body forms.<P>
<P>
(3) The scope of &quot;free&quot; declarations at the head of the <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> body <P>
is the entire <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> body (including any implicit local function <P>
definitions), but excluding initialization forms for the <A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> <P>
variables.<P>
<P>
<B>Rationale:<P>
</B><P>
Items (1) and (3) are consistent with the rules from issue <P>
<A HREF="iss092.htm">DECLARATION-SCOPE</A>.<P>
<P>
For item (2), it would be counterintuitive if declarations for <P>
<A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>CALL-NEXT-METHOD</B></A> or <A REL=DEFINITION HREF="../Body/f_next_m.htm#next-method-p"><B>NEXT-METHOD-P</B></A> that appeared at the head of <P>
a <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> body didn't actually apply to references within the body.<P>
<P>
<B>Examples:<P>
</B><P>
(1) Must the call to <A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>CALL-NEXT-METHOD</B></A> be NOTINLINE?<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_defmet.htm#defmethod"><B>defmethod</B></A> baz (...)<P>
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>declare</B></A> (<A REL=DEFINITION HREF="../Body/d_inline.htm#notinline"><B>notinline</B></A> <A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>call-next-method</B></A>))<P>
... (<A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>call-next-method</B></A>))<P>
<P>
Under proposal CORRESPONDS-TO-BINDINGS, the answer is that the<P>
declaration does apply. The <A REL=DEFINITION HREF="../Body/d_inline.htm#notinline"><B>NOTINLINE</B></A> declaration applies to<P>
the local binding of <A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>CALL-NEXT-METHOD</B></A> established within the <P>
<A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> definition, not to some outer binding that is shadowed by <P>
the local binding.<P>
<P>
(2) Is the definition of <A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>CALL-NEXT-METHOD</B></A> &quot;safe&quot;? (See issue <P>
<A HREF="iss012.htm">ARGUMENT-MISMATCH-ERROR</A> for why it might matter.)<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_defmet.htm#defmethod"><B>defmethod</B></A> baz (...)<P>
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>declare</B></A> (<A REL=DEFINITION HREF="../Body/d_optimi.htm#optimize"><B>optimize</B></A> <A REL=DEFINITION HREF="../Body/d_optimi.htm#safety"><B>safety</B></A>))<P>
... (<A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>call-next-method</B></A>))<P>
<P>
Under proposal CORRESPONDS-TO-BINDINGS, the answer is yes. The<P>
definition of <A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>CALL-NEXT-METHOD</B></A> is in the scope of the declaration.<P>
<P>
(3) Must the call to <A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>CALL-NEXT-METHOD</B></A> be NOTINLINE?<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_defmet.htm#defmethod"><B>defmethod</B></A> foo (...)<P>
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>declare</B></A> (<A REL=DEFINITION HREF="../Body/d_inline.htm#notinline"><B>notinline</B></A> <A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>call-next-method</B></A>))<P>
(generic-flet ((bar (...)<P>
(:method (...)<P>
...<P>
(<A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>call-next-method</B></A>)<P>
...)))<P>
...))<P>
<P>
Under proposal CORRESPONDS-TO-BINDINGS, the answer is no. The<P>
<A REL=DEFINITION HREF="../Body/d_inline.htm#notinline"><B>NOTINLINE</B></A> declaration is shadowed by the rebinding of <P>
<A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>CALL-NEXT-METHOD</B></A> within the nested <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> definition.<P>
<P>
<P>
<B>Current Practice:<P>
</B><P>
Chestnut's Lisp-to-C translator conforms to this proposal.<P>
<P>
It appears that PCL puts all the declarations at the head of the<P>
<A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> body at the head of the resulting lambda-expression, where<P>
they can be shadowed by the <A REL=DEFINITION HREF="../Body/s_flet_.htm#flet"><B>FLET</B></A>.<P>
<P>
Lucid 4.0 appears to scope &quot;bound&quot; declarations in accordance with<P>
this proposal, but not &quot;free&quot; declarations.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
Probably small. Note, however, that it is necessary for <A REL=DEFINITION HREF="../Body/m_defmet.htm#defmethod"><B>DEFMETHOD</B></A><P>
and <A REL=DEFINITION HREF="../Body/t_generi.htm#generic-function"><B>GENERIC-FUNCTION</B></A> to (internally) use something like PARSE-DECLARATIONS<P>
to compute their macro expansions, in order to sort out which declarations <P>
apply to which binding form. Presumably many implementations have <P>
something like that anyway, but the other cases where it's needed (<A REL=DEFINITION HREF="../Body/s_let_l.htm#letST"><B>LET*</B></A>, <P>
(<A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>LAMBDA</B></A> ...), <A REL=DEFINITION HREF="../Body/s_flet_.htm#labels"><B>LABELS</B></A>, GENERIC-LABELS) are all special forms and not<P>
macros.<P>
<P>
<B>Cost to Users:<P>
</B><P>
Probably small.<P>
<P>
<B>Cost of non-adoption:<P>
</B><P>
Continuing vagueness in the language specification.<P>
<P>
<B>Performance impact:<P>
</B><P>
Probably small.<P>
<P>
<B>Benefits:<P>
</B><P>
The cost of non-adoption is avoided.<P>
<P>
<B>Esthetics:<P>
</B><P>
See the &quot;rationale&quot;.<P>
<P>
<B>Discussion:<P>
</B><P>
The specification of <A REL=DEFINITION HREF="../Body/m_defmet.htm#defmethod"><B>DEFMETHOD</B></A> and the other method-defining forms<P>
doesn't really state explicitly that <A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>CALL-NEXT-METHOD</B></A> and <A REL=DEFINITION HREF="../Body/f_next_m.htm#next-method-p"><B>NEXT-METHOD-P</B></A><P>
are required to be locally rebound within <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> definitions that<P>
reference them. (Document 88-002R says they have &quot;lexical scope and <P>
indefinite extent&quot;.) However, it's necessary to make this point<P>
explicit so that the behavior of test case (3) is well-defined.<P>
<P>
It is assumed to be unambiguous that &quot;bound&quot; declarations that apply <P>
to the <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A>'s <A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> variables can appear at the head of the <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> <P>
body, and that the scope of the declarations is the same as the scope <P>
of the variable bindings, although 88-002R doesn't say that explicitly<P>
either.<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>