Powiel możliwe:
Tuple parameter declaration and assignment oddityZamiana dwóch Vars Scala
W Pythonie mogę zrobić
>>> (a,b) = (1,2)
>>> (b,a) = (a,b)
>>> (a,b)
(2, 1)
Ale w 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)
^
Podczas gdy ja mogę zainicjować vars jako krotkę, nie mogę przypisać ich jako krotki. Jakikolwiek sposób obejścia tego, inny niż przy użyciu tmp var?
Możliwy duplikat? http://stackoverflow.com/questions/1624484/tuple-parameter-declaration-and-assignment-oddity http://stackoverflow.com/questions/6196678/is-it-possible-to-have-tuple-assignment-to -variables-in-scala –