Swapping two vars in scala

Viewed 9994

Possible Duplicate:
Tuple parameter declaration and assignment oddity

In python I can do

>>> (a,b) = (1,2)
>>> (b,a) = (a,b)
>>> (a,b)
(2, 1)

But in scala:

Welcome to Scala version 2.8.1.final (OpenJDK Server VM, Java 1.6.0_20).
Type in expressions to have them evaluated.
Type :help for more information.

scala> var (a,b) = (1,2)
a: Int = 1
b: Int = 2

scala> (a,b)=(b,a)
<console>:1: error: ';' expected but '=' found.
       (a,b)=(b,a)
            ^

So while I can initialise vars as a tuple, I cannot assign them as a tuple. Any way to get around this, other than using a tmp var?

2 Answers
Related