Tuple redefinition
Factor handbook > The language > Objects > Tuples

Prev:Tuple introspection

In the following, the direct slots of a tuple class refers to the slot names specified in the TUPLE: form defining the tuple class, and the effective slots refers to the concatenation of the direct slots together with slots defined on superclasses.

When the effective slots of a tuple class change, all instances of the class, including subclasses, are updated.

There are three ways in which the list of effective slots may change:
Adding or removing direct slots of the class
Adding or removing direct slots of a superclass of the class
Changing the inheritance hierarchy by changing the superclass of a class
Declarations changing on existing slots

In all cases, the new effective slots are compared with the old effective slots, and each instance is updated as follows:
If any slots were removed, the values are removed from the instance and are lost forever.
If any slots were added, the instance gains these slots, all set to their initial values.
If any slots are permuted, their values in instances do not change; only the layout of the instance changes in memory.
If the slot declaration of an existing slot changes, existing values are checked to see if they are still an instance of the required class. Any which are not are replaced by the initial value of that slot.
If the number or order of effective slots changes, any BOA constructors are recompiled.

Note that if a slot is moved from a class to its superclass (or vice versa) in the same compilation unit, the value of the slot is preserved in existing instances, because tuple instance update always runs at the end of a compilation unit. However, if it is removed in one compilation unit and added in another, the value in existing instances is lost.