You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the operand on the lhs of match is left-associative. Thus we are forced to use parenthesis around the entire match block, e.g. as follows.
deff(a:String, b:B) = a + (b match {
caseThing=>"thing"caseThang=>"thang"
})
The closing parenthesis straddles such a large distance far from the original point-of-concern. Ratherifmatch was right-associative, then in the opposing case, the parenthesis are local, e.g. as follows.
```scala
deff(a:String, b:String) = (a + b) match {
case"thing"=>Thingcase"thang"=>Thang
}
Or the operand could be put on the rhs of match.
P.S. I tried to post this as a new topic at scala-debate using Google Groups, yet my new topic was automatically deleted within a few seconds of posting it. I tried 3 times. I have no problem replying to existing topics there. I don't know how to report that problem. So I am filing a report here. Note I am unable to change the "Blocker" Priority setting on this bug.
The text was updated successfully, but these errors were encountered:
@retronym said:
Please try again on the mailing list to see if you can find the history of this choice. [scala-language] would be suitable.
I don't know myself, but if I had to guess I would say it would be so you could reason about the associativy by thinking of match as a regular method:
objectTest {
def`match`(a: PartialFunction[Any, Any]) =0defop(t: Test.type) = t
this op thismatch { case x => x }
this op this `match` { case x => x }
}
qbin/scalac -Xprint:parser sandbox/test.scala
[[syntax trees at end of parser]] // test.scala
package <empty> {
object Test extends scala.AnyRef {
def <init>() = {
super.<init>();
()
};
def `match`(a: PartialFunction[Any, Any]) = 0;
this match {
case (x @ _) => x
};
def op(t: Test.type) = t;
this.op(this) match {
case (x @ _) => x
};
this.op(this).`match`(<empty> match {
case (x @ _) => x
})
}
}
Shelby Moore III (shelby) said (edited on Sep 10, 2013 7:05:40 PM UTC):
One thing I really like about getting rid of the ternary operator ( ? : ), that the silent bug of not enclosing in paired parenthesis the first operand or the entire ternary (when you need it) is avoided. The first operand comes after the if and when employed as an operand itself, an if-else clause is forced to be enclosed in parenthesis by the grammar. Unfortunately match has the first problem of the ternary (but not the second due to the required braces).
Currently the operand on the lhs of match is left-associative. Thus we are forced to use parenthesis around the entire match block, e.g. as follows.
Or the operand could be put on the rhs of match.
P.S. I tried to post this as a new topic at scala-debate using Google Groups, yet my new topic was automatically deleted within a few seconds of posting it. I tried 3 times. I have no problem replying to existing topics there. I don't know how to report that problem. So I am filing a report here. Note I am unable to change the "Blocker" Priority setting on this bug.
The text was updated successfully, but these errors were encountered: