Parallel Assignment
Some programming languages, such as JavaScript (since 1.7), Lua, occam 2, Perl, Python, REBOL, Ruby, and Windows PowerShell allow several variables to be assigned in parallel, with syntax like:
a,b := 0,1
which simultaneously assigns 0 to a
and 1 to b
. If the right-hand side of the assignment is an array variable, this feature is sometimes called sequence unpacking:
var list := {0, 1}
a,b := list
The list will be unpacked so that 0 is assigned to a
and 1 to b
. More interestingly,
a,b := b,a
Swaps the values of a
and b
. In languages without parallel assignment, this would have to be written to use a temporary variable
var t := a
a := b
b := t
since a:=b ; b:=a
leaves both a
and b
with the original value of b
.
Parallel assignment was introduced in CPL in 1963, under the name simultaneous assignment.
Read more about this topic: Assignment (computer Science)
Famous quotes containing the word parallel:
“The parallel between antifeminism and race prejudice is striking. The same underlying motives appear to be at work, namely fear, jealousy, feelings of insecurity, fear of economic competition, guilt feelings, and the like. Many of the leaders of the feminist movement in the nineteenth-century United States clearly understood the similarity of the motives at work in antifeminism and race discrimination and associated themselves with the anti slavery movement.”
—Ashley Montagu (b. 1905)