Skip to main content

Constructor Field Assignment



Assignment to a field of a constructor.


Exp₁ [ FieldName = Exp₂ ]


Exp₁ should evaluate to a constructor with a field named Name. Statically the type should either be a assign the value of Exp₂ to that field

Field assignment applies to all values that have named components like tuples and relations with named elements, data types, and locations. Field assignment returns a new value in which the named component has been replaced by a new value. Name stands for itself and is not evaluated.


rascal>data Example
>>>>>>> = example(int key, str val="<key>");
rascal>T = example(42);
Example: example(42)
int: 42

Observe that field assignment creates a new value with an updated field. The old value remains unchanged as can be seen from the unchanged value of T in the above example.