Slot class declarations
Factor handbook > The language > Objects > Tuples > Tuple slot declarations

Prev:Read-only slots
Next:Initial values of slots


Class declaration is optional, and the default value is object, the class of all objects. If a more specific class is declared, then the object system maintains an invariant that the value of the slot must always be an instance of the class, even during construction. This invariant is enforced at a number of locations:
Writer words (Slot accessors) throw an error if the new value does not satisfy the class predicate.
The new word fills in slots with their initial values; the (per-class) initial values are required to satisfy the class predicate.
The boa word ensures that the values on the stack satisfy the class predicate.
Mirrors ensure that the value passed to set-at satisfies the class predicate.
The slots>tuple and >tuple words ensure that the values in the sequence satisfy the correct class predicates.
Tuple redefinition fills in new slots with initial values and ensures that changes to existing declarations result in incompatible values being replaced with the initial value of their respective slots.

Coercive slot declarations

The Maybe classes are a useful way to specify class for an optional slot.