Skip to main content

Constructor Field Assignment

rascal-0.40.17

Synopsis

Assignment to a field of a constructor.

Syntax

Exp₁ [ FieldName = Exp₂ ]

Description

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.

Examples

rascal>data Example
>>>>>>> = example(int key, str val="<key>");
ok
rascal>T = example(42);
Example: example(42)
rascal>T.key
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.