Primary
Parallel Assignment ○|Definition|1st|20260101171559-00-⌔
Assignment (computer science) - Wikipedia#Parallel_assignment
Parallel assignment
Some programming languages, such as APL, Common Lisp,1 Go,2 JavaScript (since 1.7)3, Julia, PHP, Maple, Lua, occam 2,4 Perl,5 Python,6 REBOL, Ruby,7 and PowerShell allow several variables to be assigned in parallel, with syntax like:
a, b := 0, 1which simultaneously assigns 0 to
aand 1 tob. This is most often known as parallel assignment; it was introduced in CPL in 1963, under the name simultaneous assignment,8 and is sometimes called multiple assignment, though this is confusing when used with “single assignment”, as these are not opposites. If the right-hand side of the assignment is a single variable (e.g. an array or structure), the feature is called unpacking9 or destructuring assignment:10var list := {0, 1} a, b := listThe list will be unpacked so that 0 is assigned to
aand 1 tob. Furthermore,a, b := b, aswaps the values of
aandb. In languages without parallel assignment, this would have to be written to use a temporary variablevar t := a a := b b := tsince
a:= b; b:= aleaves bothaandbwith the original value ofb.Some languages, such as Go, F# and Python, combine parallel assignment, tuples, and automatic tuple unpacking to allow multiple return values from a single function, as in this Python example,
def f() -> tuple[int, int]: return 1, 2 a: int b: int a, b = f()while other languages, such as C# and Rust, shown here, require explicit tuple construction and deconstruction with parentheses:
// Valid C# or Rust syntax (a, b) = (b, a);// C# tuple return (string, int) f() => ("foo", 1); var (a, b) = f();// Rust tuple return let f: fn() -> (&str, i32) = || ("foo", 1); let (a, b): (&str, i32) = f();This provides an alternative to the use of output parameters for returning multiple values from a function. This dates to CLU (1974), and CLU helped popularize parallel assignment generally.
C# additionally allows generalized deconstruction assignment with implementation defined by the expression on the right-hand side, as the compiler searches for an appropriate instance or extension
Deconstructmethod on the expression, which must have output parameters for the variables being assigned to.11 For example, one such method that would give the class it appears in the same behavior as the return value off()above would bevoid Deconstruct(out string a, out int b) { a = "foo"; b = 1; }In C and C++, the comma operator is similar to parallel assignment in allowing multiple assignments to occur within a single statement, writing
a = 1, b = 2instead ofa, b = 1, 2. This is primarily used in for loops, and is replaced by parallel assignment in other languages such as Go.12 However, the above C++ code does not ensure perfect simultaneity, since the right side of the following codea = b, b = a+1is evaluated after the left side. In languages such as Python,a, b = b, a+1will assign the two variables concurrently, using the initial value of a to compute the new b.Printed 2026-06-28.
(echo:: @ ᯤ)
Link to original Footnotes
“CLHS: Macro SETF, PSETF”. Common Lisp Hyperspec. LispWorks. Retrieved 23 April 2019. ↩
The Go Programming Language Specification: Assignments ↩
Fitzgerald, Nick; Orendorff, Jason. “ES6 In Depth: Destructuring”. Mozilla Hacks. Retrieved 3 December 2025. ↩
INMOS Limited, ed. (1988). Occam 2 Reference Manual. New Jersey: Prentice Hall. ISBN 0-13-629312-3. ↩
Wall, Larry; Christiansen, Tom; Schwartz, Randal C. (1996). Perl Programming Language (2 ed.). Cambridge: O´Reilly. ISBN 1-56592-149-6. ↩
Lutz, Mark (2001). Python Programming Language (2 ed.). Sebastopol: O´Reilly. ISBN 0-596-00085-5. ↩
Thomas, David; Hunt, Andrew (2001). Programming Ruby: The Pragmatic Programmer’s Guide. Upper Saddle River: Addison Wesley. ISBN 0-201-71089-7. ↩
D.W. Barron et al., “The main features of CPL”, Computer Journal 6:2:140 (1963). full text (subscription) ↩
“PEP 3132 — Extended Iterable Unpacking”. legacy.python.org. Retrieved 20 April 2018. ↩
“Destructuring assignment”. MDN Web Docs. Retrieved 20 April 2018. ↩
“Deconstructing tuples and other types”. Microsoft Docs. Microsoft. Retrieved 29 August 2019. ↩
Effective Go: for, “Finally, Go has no comma operator and ++ and — are statements not expressions. Thus if you want to run multiple variables in a for you should use parallel assignment (although that precludes ++ and —).” ↩
Secondary
• • •