Skip to main content

Subscription

rascal-0.34.0

Synopsis

Assign a single element of a structured value.

Description

Let V be the current value of Assignable. The value of Exp₁ is used as index in V and the value of Exp₂ replaces the original value at that index position. The result is a new value V' that is assigned to the Assignable.

Examples


Assignable has a list value:

rascal>L = [10,20,30];
list[int]: [10,20,30]
rascal>P = L;
list[int]: [10,20,30]
rascal>L[1] = 200;
list[int]: [10,200,30]

Observe that P is unchanged:

rascal>P;
list[int]: [10,20,30]

Assignable has a map value:

rascal>M = ("abc": 1, "def" : 2);
map[str, int]: ("abc":1,"def":2)
rascal>M["def"] = 3;
map[str, int]: ("abc":1,"def":3)

Assignable has a tuple value:

rascal>T = <1, "abc", true>;
tuple[int,str,bool]: <1,"abc",true>
rascal>T[1] = "def";
tuple[int,str,bool]: <1,"def",true>

NOTE: See https://github.com/usethesource/rascal/issues/948