Is the last level of a dictionary not copied as a reference?

a={b={c=1}}
q=a.b.c
q=2 -- a.b.c = 1
q=a.b
q.c=2 -- a.b.c = 2

Just to confirm, is the behavior above correct?
That is, if I want to modify the contents of an original table through an “alias” variable, is this not possible if I reference its last level?

Yes that’s how it works. (Number Number one)

1 Like

base types are copied, these are number, string, and boolean. All other types are referenced.

when you write a.b.c that gets the value 1 which is typeof(1) == "number" so it is copied to q, and alterations to the copy do not affect the original

when you write a.b that value is {c} which is typeof({c}) == "table" so it creates a reference and alterations to it’s properties are carried over.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.