Possible Duplicate:
Tuple parameter declaration and assignment oddity
In Scala, one can do multiple-variable assignment to tuples via:
val (a, b) = (1, 2)
But a similar syntax for assignment to variables doesn’t appear to work. For example I’d like to do this:
var (c, d) = (3, 4)
(c, d) = (5, 6)
I’d like to reuse c and d in multiple-variable assignment. Is this possible?
This isn’t simply “multiple variable assignment”, it’s fully-featured pattern matching!
So the following are all valid:
This is the way that pattern matching works, it’ll de-construct something into smaller parts, and bind those parts to new names. As specified, pattern matching won’t bind to pre-existing references, you’d have to do this yourself.