Select a field from a constructor by its field name.
Exp . Name
Field selection applies to constructors with named elements such as fields and keyword fields. Exp should evaluate to a tuple with field Name and returns the value of that field. Name stands for itself and is not evaluated.
Because the types of field names are known statically, field projection for constructors produces
values of precise types. This is unlike FieldSelection where the resulting type is always
Constructor keyword fields have
default expressions which can be dependent on each other and
on the positional fields (by name). They are computed lazily upon request.
rascal>data Example = example(int key, str val="<key>"); ❶
rascal>t = example(42);
rascal>t.key = 2;
rascal>t.key += 2;
valis a keyword field with a default value computed from the positional field
- constructors with fields are a versatile way of modeling and storing hierarchical data