scala> val a@b = new Object
a: java.lang.Object = java.lang.Object@80b973
b: java.lang.Object = java.lang.Object@80b973
Notice that the variables above get initialized with the same value, as opposed to:
scala> val a,b = new Object
a: java.lang.Object = java.lang.Object@d1223d
b: java.lang.Object = java.lang.Object@1ee8c1
Also possible with ´var´s and with more than two names (but not with ´def´s):
scala> var a@(b@(c@d)) = new Object
a: java.lang.Object = java.lang.Object@cbbdf3
b: java.lang.Object = java.lang.Object@cbbdf3
c: java.lang.Object = java.lang.Object@cbbdf3
d: java.lang.Object = java.lang.Object@cbbdf3
Enjoy :)
--
EL
Of course! (Just in case it was not a purely ritorical polite phrase)
Probably, not. IIUC the grammar doesn't allow for chained bindings.
I looked again into the grammar, and still see no way how to come from a ´Pattern3´ (in the
´Pattern2´ rule) to a chain ´id @ ...´ (or ´varid @ ...´) to make possible a definition without
parentheses.
Here is the relevant snippet:
PatVarDef ::= ‘val’ PatDef
| ‘var’ VarDef
PatDef ::= Pattern2 {‘,’ Pattern2} [‘:’ Type] ‘=’ Expr
VarDef ::= PatDef
| ids ‘:’ Type ‘=’ ‘_’
Pattern2 ::= varid [‘@’ Pattern3]
| Pattern3
Pattern3 ::= SimplePattern
| SimplePattern { id [nl] SimplePattern }
SimplePattern ::= ‘_’
| varid
| Literal
| StableId
| StableId ‘(’ [Patterns] ‘)’
| StableId ‘(’ [Patterns ‘,’] [varid ‘@’] ‘_’ ‘*’ ‘)’
| ‘(’ [Patterns] ‘)’
| XmlPattern
varid ::= lower idrest
Path ::= StableId
| [id ‘.’] ‘this’
StableId ::= id
| Path ‘.’ id
| [id ’.’] ‘super’ [ClassQualifier] ‘.’ id
--
EL