[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ISSUE: DEFSTRUCT-REDEFINITION



Issue:          DEFSTRUCT-REDEFINITION
References:     
Category:       CLARIFICATION
Edit history:   Revision 1 by Skona Brittain 07/26/88


Problem Description:

The case of a structure type being redefined is not discussed in CLtL.


Proposal (DEFSTRUCT-REDEFINITION:ERROR-ITSELF):

It is an error to redefine a structure.

Proposal (DEFSTRUCT-REDEFINITION:ERROR-IFF-OLD-USE):

Redefining a structure is ok but it is an error to access, in any way,
an instance of the structure that was created prior to the redefinition.
This applies to instances of other structures that :INCLUDEd the 
redefined structure. 
It is also an error to use any of the redefined structures accessors
on any instances of a structure that :INCLUDEd the previous definition.


Test Cases:

(I)
(defstruct struc1
   slot1 slot2)
(setq s (make-struc1 :slot1 1 :slot2 2))
(defstruct struc1  ; this is an error according to ERROR-BY-ITSELF
   slot2 slot1)    ;          but not according to ERROR-IFF-USE
(struc1-slot1 s)   ; this is an error according to ERROR-IFF-USE

(II)
(defstruct struc1
   slot1 slot2)
(defstruct (struc2 (:include struc1))
  slot 3)
(defstruct struc1
  slot2 slot1)
(setq s (make-struc2 :slot1 1 :slot2 2))
(struc1-slot1 s)   ; this is an error according to ERROR-IFF-USE


Rationale:

The issue of redefinition should be addressed since there are always 
consequences that affect use of the structures: at the very least, 
the constructor function gets overwritten when a structure is redefined.

ERROR-BY-ITSELF is simpler, but ERROR-IFF-USED is more amenable to use.


Current Practice:

None of KCL, Lucid, & Symbolics detect a redefinition, but all of them
return 2 as the value of the last forms in each of the above test case sets.


Cost to Implementors:

ERROR-ITSELF:  none if not signaled. extremely slight if signaled.

ERROR-IFF-OLD-USE:  none if not signaled. much more if signaled.


Cost to Users:

ERROR-ITSELF:  It can be quite inconvenient to be prevented from "correcting"
a structure definition, which would presumably happen if the error were 
signaled.

ERROR-IFF-OLD-USE:  None.


Cost of Non-Adoption:

Confusion.


Benefits:

Clarity.


Aethetics:

Something that is not well-defined and leads to erratic behavior 
should be explicitly considered an error.


Discussion: 

Larry supports ERROR-BY-ITSELF, "in that slot-accessors for structures are 
presumed to be declared "inline".  If users want more flexibility than that, 
they should use defclass."

Various inbetween proposals are possible, such as only incompatible 
redefinitions cause errors, but they're too hard to define.

My feeling is that it's a cop-out to just say it's an error to redefine
a structure but then never signal the error - users will still be confused
by the differing seemingly erratic behavior and code.