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

146 lines
9.4 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 LOCALLY-TOP-LEVEL 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/iss218_w.htm">
<LINK REL=UP HREF="../Issues/iss219.htm">
<LINK REL=NEXT HREF="../Issues/iss220_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/iss218_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss219.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss220_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue LOCALLY-TOP-LEVEL Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss219.htm">LOCALLY-TOP-LEVEL</A><P>
<P>
<B>References:</B> None<P>
<P>
Related issues: <A HREF="iss147.htm">EVAL-WHEN-NON-TOP-LEVEL</A>, <A HREF="iss092.htm">DECLARATION-SCOPE</A><P>
<P>
<B>Category:</B> CLARIFICATION / ADDITION<P>
<P>
<B>Edit history:</B> Version 1, 9-Mar-89, by Moon<P>
Version 2, 16-Mar-89, by Moon, fix referenced proposal name<P>
<P>
<B>Problem description:<P>
</B><P>
It is desirable to be able to wrap <A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>LOCALLY</B></A> around one or more<P>
top-level forms and have them continue to be treated as top-level<P>
forms. Three examples of how this is useful:<P>
<P>
- to put an <A REL=DEFINITION HREF="../Body/d_optimi.htm#optimize"><B>OPTIMIZE</B></A> or <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> declaration into force around<P>
several related forms.<P>
<P>
- to put declarations into force around <A REL=DEFINITION HREF="../Body/m_defcla.htm#defclass"><B>DEFCLASS</B></A>, or any other<P>
top-level form that lacks a syntax for embedded declarations.<P>
<P>
- <A HREF="iss092.htm">DECLARATION-SCOPE:NO-HOISTING</A>, which passed in January,<P>
removed the ability to use a <A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> at the head of the body of a<P>
<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>DEFUN</B></A> or <A REL=DEFINITION HREF="../Body/m_defmac.htm#defmacro"><B>DEFMACRO</B></A> to make a declaration that applies to the entire<P>
form, including the lambda-list. We are supposed to use <A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>LOCALLY</B></A><P>
instead, but forms in the body of <A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>LOCALLY</B></A> are not top-level,<P>
and that changes the semantics of <A REL=DEFINITION HREF="../Body/m_defmac.htm#defmacro"><B>DEFMACRO</B></A>.<P>
<P>
Issue <A HREF="iss147.htm">EVAL-WHEN-NON-TOP-LEVEL</A> could not define <A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>LOCALLY</B></A> to treat<P>
its body as top-level forms, because only a special form can do<P>
that and <A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>LOCALLY</B></A> is a macro.<P>
<P>
<B>Proposal (LOCALLY-TOP-LEVEL:SPECIAL-FORM):<P>
</B> <P>
Change <A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>LOCALLY</B></A> from a macro to a special form, and change the<P>
definition of compiler processing (in <A HREF="iss147.htm">EVAL-WHEN-NON-TOP-LEVEL</A>)<P>
so that when a <A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>LOCALLY</B></A> form appears at top level the forms in<P>
its body are processed at top level.<P>
<P>
<B>Examples:<P>
</B><P>
(<A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>locally</B></A> (<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> 3) (<A REL=DEFINITION HREF="../Body/d_optimi.htm#space"><B>space</B></A> 3) (<A REL=DEFINITION HREF="../Body/d_optimi.htm#speed"><B>speed</B></A> 0)))<P>
(<A REL=DEFINITION HREF="../Body/m_defmac.htm#defmacro"><B>defmacro</B></A> frob (<A REL=DEFINITION HREF="../Body/03_dd.htm#AMenvironment"><B>&amp;environment</B></A> e x y <A REL=DEFINITION HREF="../Body/03_da.htm#AMoptional"><B>&amp;optional</B></A> (z (foo x y)))<P>
(mumble x y z e)))<P>
<P>
Without this proposal, this would have to be written<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_defmac.htm#defmacro"><B>defmacro</B></A> frob (<A REL=DEFINITION HREF="../Body/03_dd.htm#AMenvironment"><B>&amp;environment</B></A> e x y <A REL=DEFINITION HREF="../Body/03_da.htm#AMoptional"><B>&amp;optional</B></A> (z (<A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>locally</B></A><P>
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>declare</B></A><P>
(<A REL=DEFINITION HREF="../Body/d_optimi.htm#optimize"><B>optimize</B></A><P>
(<A REL=DEFINITION HREF="../Body/d_optimi.htm#safety"><B>safety</B></A> 3)<P>
(<A REL=DEFINITION HREF="../Body/d_optimi.htm#space"><B>space</B></A> 3)<P>
(<A REL=DEFINITION HREF="../Body/d_optimi.htm#speed"><B>speed</B></A> 0)))<P>
(foo x y))))<P>
(<A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>locally</B></A> (<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> 3) (<A REL=DEFINITION HREF="../Body/d_optimi.htm#space"><B>space</B></A> 3) (<A REL=DEFINITION HREF="../Body/d_optimi.htm#speed"><B>speed</B></A> 0)))<P>
(mumble x y z e)))<P>
<P>
<B>Rationale:<P>
</B><P>
Wrapping <A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>LOCALLY</B></A> around a form should not change its semantics except<P>
as specified by the declarations, hence the body of a top-level<P>
<A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>LOCALLY</B></A> should be top-level.<P>
<P>
A macro cannot have a top-level body unless it expands into a special<P>
form that has a top-level body; otherwise the macro invocation and<P>
the macro expansion would not have identical semantics as top-level<P>
forms. There is no available special form for <A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>LOCALLY</B></A> to <A REL=DEFINITION HREF="../Body/f_mexp_.htm#macroexpand"><B>macroexpand</B></A><P>
into (CLtL doesn't say, but presumably the intent was to expand into<P>
a <A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>LET</B></A> with an empty binding list).<P>
<P>
<B>Current practice:<P>
</B><P>
The Zetalisp equivalent of <A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>LOCALLY</B></A> worked to surround top-level forms,<P>
because it was a macro that expanded into COMPILER-LET (stashing the<P>
declarations in a special variable the compiler would look at). This<P>
is of course the wrong way to do declarations, but it shows that the<P>
idea was that you could wrap declarations around a bunch of top-level<P>
forms.<P>
<P>
Symbolics Genera 7.4.0 does not implement the proposal (but it does<P>
not implement <A HREF="iss092.htm">DECLARATION-SCOPE:NO-HOISTING</A> either). I did<P>
not survey any other implementations.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
A half dozen lines of code in the compiler and a smaller amount<P>
in the interpreter and any program-analyzing programs.<P>
<P>
<B>Cost to Users:<P>
</B><P>
None.<P>
<P>
<B>Cost of non-adoption:<P>
</B><P>
See the horrible example above.<P>
<P>
<B>Performance impact:<P>
</B><P>
None.<P>
<P>
<B>Benefits:<P>
</B><P>
More consistent language.<P>
<P>
<B>Esthetics:<P>
</B><P>
Improved.<P>
<P>
<B>Discussion:<P>
</B><P>
None.<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>