159 lines
10 KiB
HTML
159 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 DEFSTRUCT-REDEFINITION 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/iss117_w.htm">
|
|
<LINK REL=UP HREF="../Issues/iss118.htm">
|
|
<LINK REL=NEXT HREF="../Issues/iss119_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/iss117_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss118.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss119_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2>Issue DEFSTRUCT-REDEFINITION Writeup</H2>
|
|
|
|
<PRE><B>Status:</B> Passed (as amended) Jan 89 X3J13<P>
|
|
<B>Issue:</B> <A HREF="iss118.htm">DEFSTRUCT-REDEFINITION</A><P>
|
|
<B>References:</B> <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> (CLtL pp 305-320)<P>
|
|
Related-issues: DEFSTRUCT-ACCESS-FUNCTIONS-INLINE<P>
|
|
<B>Category:</B> CLARIFICATION<P>
|
|
<B>Edit history:</B> Version 1 by Skona Brittain 07/26/88<P>
|
|
Version 2 by Larry Masinter 7-Jan-89<P>
|
|
Version 3 by Masinter 6-Feb-89 as per Jan 89 X3J13 amendment<P>
|
|
<P>
|
|
<B>Problem Description:<P>
|
|
</B><P>
|
|
The case of a <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> type being redefined is not discussed in CLtL. Is<P>
|
|
it legal to redefine a DEFSTRUCT? What happens to DEFSTRUCTS that :INCLUDE<P>
|
|
the one defined. What things might be "wired in" in compiled code that<P>
|
|
refered to the previous DEFSTRUCT?<P>
|
|
<P>
|
|
<B>Proposal: (DEFSTRUCT-REDEFINITION:ERROR):<P>
|
|
</B><P>
|
|
The results of redefining a <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> are undefined.<P>
|
|
<P>
|
|
<B>Rationale:<P>
|
|
</B><P>
|
|
<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> is intended as "the most efficient" <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> <A REL=DEFINITION HREF="../Body/t_class.htm#class"><B>class</B></A>. <A REL=DEFINITION HREF="../Body/m_defcla.htm#defclass"><B>DEFCLASS</B></A><P>
|
|
allows much more flexible structures to be defined. Thus, implementations<P>
|
|
should be free to "wire in" much of the behavior of a <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> into<P>
|
|
compiled code.<P>
|
|
<P>
|
|
The issue of redefinition should be addressed since there are always<P>
|
|
consequences that affect use of the structures.<P>
|
|
<P>
|
|
<B>Current Practice:<P>
|
|
</B><P>
|
|
None of KCL, Lucid, & Symbolics detect a redefinition.<P>
|
|
<P>
|
|
Envos Medley goes to some effort to detect if a new <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> is<P>
|
|
"compatible" with the old -- e.g., slots might change names, initial<P>
|
|
values, but, since the space allocated in an instance is determined by the<P>
|
|
:TYPE, an incompatible set of :TYPE forms would cause old instances to be<P>
|
|
marked "obsolete". (The <A REL=DEFINITION HREF="../Body/f_tp_of.htm#type-of"><B>TYPE-OF</B></A> an old instance changes to **OBSOLETE**,<P>
|
|
for example.)<P>
|
|
<P>
|
|
<B>Cost to Implementors:<P>
|
|
</B><P>
|
|
This proposal attempts to be consistent with current practice.<P>
|
|
<P>
|
|
<B>Cost to Users:<P>
|
|
</B><P>
|
|
It is doubtful that any current programs actually define structures more<P>
|
|
than once. Thus, constraints on <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> redefinition primarily affect the<P>
|
|
debugging environment.<P>
|
|
<P>
|
|
<B>Cost of Non-Adoption:<P>
|
|
</B><P>
|
|
Confusion.<P>
|
|
<P>
|
|
<B>Benefits:<P>
|
|
</B><P>
|
|
Clarity.<P>
|
|
<P>
|
|
<B>Aethetics:<P>
|
|
</B><P>
|
|
Something that is not well-defined and leads to erratic behavior should be<P>
|
|
explicitly considered an error.<P>
|
|
<P>
|
|
<B>Discussion: <P>
|
|
</B><P>
|
|
Common implementation techniques may cause the following behavior if a<P>
|
|
<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> is redefined:<P>
|
|
<P>
|
|
If the new <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> is identical to the old <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> except for the<P>
|
|
initialization forms for slots, previous <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> objects probably can<P>
|
|
continue to be accessed with previously compiled slot accessors. <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A><P>
|
|
constructor, test functions are proclaimed <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A>, and if these have<P>
|
|
changed, previously compiled occurrences of them may behave unpredictably.<P>
|
|
<P>
|
|
If any change is made to the definiton of the slots (either in number,<P>
|
|
name, or :TYPE), attempting to execute a slot accessor of the old<P>
|
|
definition may behave unpredictably: if a slot name of the old definition<P>
|
|
also names a slot of the new definition, any "compiled" code might use the<P>
|
|
old definition instead. <P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> constructor, test functions may also be proclaimed <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A>, and<P>
|
|
may behave unpredictably if previously compiled. In particular, a compiled<P>
|
|
occurance of a constructor might have the previously slot initial values<P>
|
|
"wired in".<P>
|
|
<P>
|
|
If the new <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> differs from the old in any aspect other than the<P>
|
|
initialization forms for slots, the results of attempting to access any old<P>
|
|
instance might result in unspecified behavior. For example, if the size of<P>
|
|
the <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> became considerably shorter, an old accessor might "access<P>
|
|
off the end" of an instance of a new object; it might signal an error or<P>
|
|
have other unpredictable results.<P>
|
|
<P>
|
|
Masinter supports this proposal. If users want more flexibility than<P>
|
|
<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> allows, they should use <A REL=DEFINITION HREF="../Body/m_defcla.htm#defclass"><B>DEFCLASS</B></A>.<P>
|
|
<P>
|
|
Some felt strongly that just saying it's an error to redefine a <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A><P>
|
|
but not requiring the error to be signalled will cause users to be confused<P>
|
|
by the differing seemingly erratic behavior and code. <P>
|
|
<P>
|
|
Programming environments are allowed, encouraged, etc. to allow such<P>
|
|
redefinition, perhaps with warning messages. It is beyond the scope of the<P>
|
|
language <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A> to define those interactions, except to note that they<P>
|
|
are not portable. <P>
|
|
<P>
|
|
Here's an example where reexecuting an <A REL=DEFINITION HREF="../Body/f_equal.htm#equal"><B>EQUAL</B></A> <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> might result in<P>
|
|
different behavior:<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_defpar.htm#defvar"><B>defvar</B></A> *token-counter* 0)<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>defstruct</B></A> token (cookie '("unique-string")) (counter (<A REL=DEFINITION HREF="../Body/m_incf_.htm#incf"><B>incf</B></A><P>
|
|
*token-counter*)))<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_defpar.htm#defvar"><B>defvar</B></A> *first-token* (make-token))<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/a_eql.htm#eql"><B>eql</B></A> (token-cookie *first-token*) (token-cookie (make-token))) => true<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>defstruct</B></A> token (cookie '("unique-string")) (counter (<A REL=DEFINITION HREF="../Body/m_incf_.htm#incf"><B>incf</B></A><P>
|
|
*token-counter*)))<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/a_eql.htm#eql"><B>eql</B></A> (token-cookie *first-token*) (token-cookie (make-token))) => false<P>
|
|
<P>
|
|
I.e., even though the second <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> is <A REL=DEFINITION HREF="../Body/f_equal.htm#equal"><B>EQUAL</B></A> to the first, the<P>
|
|
structures are not <A REL=DEFINITION HREF="../Body/a_eql.htm#eql"><B>EQL</B></A>.<P>
|
|
<P>
|
|
This is related to the compiler issue QUOTE-MAY-COPY, but is not the same<P>
|
|
issue, since that proposal isn't proposing that <A REL=DEFINITION HREF="../Body/s_quote.htm#quote"><B>QUOTE</B></A> might copy its value<P>
|
|
*every time* it is executed.<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>
|