3 ms·
Python: (a, b) = (b + 1, a + 1) The two expressions that add 1 are evaluated first, a tuple containing the anonymous results is created, which is unpacked
by rzzzwilson 4y ago
Python:
(a, b) = (b + 1, a + 1)
The two expressions that add 1 are evaluated first, a tuple containing the anonymous results is created, which is unpacked and assigned to the names on the left side. This sidesteps the problem of old/new values.
- aappleby 4y agoThat works for the trivial example, but in a larger program I can't realistically say (a,b,c,d,e,f......zzz) = (....) to get the equivalent of an "atomic" update to the program's state.
- rzzzwilson 4y agoThen don't do that. Python also has mechanisms for handling sequences of values, passing them to functions, etc. But that's getting off the point of your question. You asked "what programming languages ...?". I gave an example of how the python language gets around the problem scenario you used as an example. I'm not suggesting you use python or any other language, just providing one answer to your question.