(field pat (? init)) pat: a pattern init: any form (optional)
Defines one or more fields.
The arguments to field
are similar to let
: the initializer is optional, and
(field a b c d)
is equivalent to (field a b)
followed by (field c d)
.
pat
must introduce at least one name binding. Each such binding is allocated some
storage within each object of this class. Name collisions within the same
state are forbidden.
Object fields can be read or written using []
, just like a table.
When an initializer form is present, it will automatically be executed at the beginning of the state's initializer method.
When two fields in different states share the same unqualified name, and that unqualified
name is passed to []
or @
, one field will shadow the other:
- Child states always shadow their parent state.
- Between sibling states, or within a single state, fields defined textually later shadow those which were defined earlier.
- Fields defined in mixins are considered to be "textually earlier" than those defined
inline in the class. Between two mixins, those towards the left of the
mixin
clause are textually earlier than those towards the right.
Name shadowing can be bypassed by referring to a field by its qualified name,
StateName:item
, rather than its unqualified name, item
. Fields defined at the toplevel
of a class prefix their qualified name with Main:
. Fields defined at the toplevel of
a mixin prefix their qualified name with MixinName:
.