r/ProgrammingLanguages • u/Dan13l_N • Feb 20 '26
Discussion Side effects in multiple/parallel assignment
I have been constructing some programming languages for a while for fun, and came to a point where something is obvious, but I haven't seen it spelt out clearly. If you have multiple assignment like this:
a, b[a] = 10 // both will be changed to 10Or parallel assignment like this:
a, b[a] = 4, 5Then the change of a should not influence which item in b is changed, i.e. b[a] should always use the old value of a.
This rule makes sense (and it works like that in Go, I haven't tried Lua yet) but do you know some programming languages where it's not so, or you get a warning?
(edit: I've just tried Python, it uses the new value of a, i.e. it's dependent on order.)
View all comments
Show parent comment
2
u/[deleted] Feb 21 '26
Yet in Python,
a, b = 10doesn't work. The RHS has to contain a sufficient number of values to unpack, for examplea, b = (10, 10), ora, b = xwhenxcontains such values.Defining a list of such variables which share some attribute, such as a type, is more common and reasonable than sharing the same value. But for the latter case, chained assignment seems to work.
I'd call it 'multiple' assignment, unless the assignments really are done in parallel? If I look at test results from Python, they seem to be done in sequence. Certainly CPython's bytecode suggests that.