Nested dictionary in VEX showing unexpected behavior.

   510   4   0
User Avatar
Member
11 posts
Joined: 4月 2011
Offline
Good Day Community.

I was under the impression that in VEX, variables are passed by reference.

Then, can anyone please explain why it's not the case in the following example, ie: once b is passed to a, any further updates to b is not reflected in a's reference(or copy) of b?

dict a = set('name', 'A');
dict b = set('name', 'B');
dict c = set('name', 'C');

a['next'] = b;
b['next'] = c;

printf(a['name']);                        // Output 'A', as expected;
printf(a['next']['name']);                // Output 'B', as expected;
printf(b['next']['name']);                // Output 'C', as expected;
printf(a['next']['next']['name']);        // Output nothing, expected output 'C'.

An equivalent example in Python, with expected output would be:

a = dict(name = 'A')
b = dict(name = 'B')
c = dict(name = 'C')

a['next'] = b
b['next'] = c

print(a['name'])                        # Output A, as expected;
print(a['next']['name'])                # Output B, as expected;
print(b['next']['name'])                # Output C, as expected;
print(a['next']['next']['name'])        # Output C, as expected.

Thank you, for any advice/insights you may provide.
Edited by aeonzeon - 2024年9月12日 14:44:44
User Avatar
Member
8772 posts
Joined: 7月 2007
Offline
aeonzeon
I was under the impression that in VEX, variables are passed by reference.
they are passed by reference to functions when used as arguments

but assignment using = will pass evaluated value
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
11 posts
Joined: 4月 2011
Offline
Then, is there anyway/noway to achieve in VEX the same behavior as in the Python example above?

Thank you.
User Avatar
Member
297 posts
Joined: 1月 2013
Offline
aeonzeon
Then, is there anyway/noway to achieve in VEX the same behavior as in the Python example above?

Thank you.

If you change the order of assignment
b['next'] = c;
a['next'] = b;
User Avatar
Member
11 posts
Joined: 4月 2011
Offline
Ah! Right!

Thank you.
  • Quick Links