Field Assignment
rascal-0.40.17
Synopsis
Assignment to a field of a tuple or datatype.
Syntax
Exp₁ [ FieldName = Exp₂ ]
Description
Exp₁ should evaluate to a tuple or 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 constructors with named elements, 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>node T = "name"(1, x="abc");
node: "name"(1,
x="abc")
rascal>T[x = "def"];
node: "name"(1,
x="def")
rascal>T
node: "name"(1,
x="abc")
rascal>T = T[x="def"];
node: "name"(1,
x="def")
rascal>T
node: "name"(1,
x="def")
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.