Ah, I think I see.
- In the ’mydict.data[0][1]:5
case, Lil traces from the originalmydict` variable down into the nested list, and so after creating an updated sublist, it can trace all the way back up to the original variable and update that too. - In the
field1.data[0][1]:5case,field1.dataproduces a data structure out of (from Lil’s point of view) thin air, and so Lil doesn’t know how to update it.
Is that right?
If the root of the expression is a variable, its contents is updated. In some cases this may look like a mutation, but anything that referred to the original value will still see the unmodified copy…
I originally tried to illustrate Lil’s immutable, functional nature by modifying a nested value and showing the original variable still had its original value, but… Lil was too smart for me, and the variable was updated to point at the modified value. I also considered using the “assign A to B, modify A, B is unchanged” example, but that just looks like a copy of the value is made immediately, rather than being copy-on-write.
I am still amused by the irony that interfaces make a better illustration of Lil’s immutable values, for the wrong reason. :)