I'm just wondering what the reason is for making a variable set to a pre-existing table actually be a reference to the same table, rather than a copy. For instance:
a = 1
b = a
b = 2
print(a)
> 1
Makes sense, because b was just set to have the same value as 'a'
a = {1}
b = a
b[1] = 2
print(a[1])
> 2
Does this happen just because tables are assigned a specific slot in the memory, whereas numbers are just... intuitive, or something? I'm just curious why there's the discrepancy. |