Why can I not edit a map value assigned to another variable?

The following code modifies the array in a.

      let a = ("fda": (1,2,3))
      a.at("fda").push(4)

The following code does not, why?

      let a = ("fda": (1,2,3))
      let b = a.at("fda")
      b.push(4)

V 0.13.0

When assigning to a variable, you will actually get a copy of the array (in reality, it’s a bit more complicated iirc but it doesn’t matter in practice)
In the first case however, you directly access the value in the dictionary, thus modifying it

1 Like

can I avoid creating a copy when assigning to a variable?

No you cannot (afaik), as that would probably break function purity, although I’m not sure that is the reason for this design choice

1 Like