Initial values of slots
Factor handbook » The language » Objects » Tuples » Tuple slot declarations

Prev:Slot class declarations

An initial value for a slot can be specified with the initial: slot declaration attribute. For certain classes, the initial value is optional; in these cases, it does not need to be specified. For others, it is required. Initial values can be used independently of class declaration, but if specified, the value must satisfy the class predicate.

The following classes have default initial values:
byte-arrayB{ }

All other classes are handled with one of two cases:
If the class is a union or mixin class which contains one of the above known classes, then the initial value of the class is that of the known class, with preference given to classes earlier in the list. For example, if the slot is declared object (this is the default), the initial value is f. Similarly for sequence and assoc.
If the class is a tuple class, the initial value of the slot is a new, shared instance of the class created with new.
Otherwise, a bad-initial-value error is thrown. In this case, an initial value must be specified explicitly using initial:.

A word can be used to check if a class has an initial value or not:
initial-value ( class -- object ? )