Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change match syntax #7610

Merged
merged 7 commits into from Nov 29, 2019
Merged

Change match syntax #7610

merged 7 commits into from Nov 29, 2019

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Nov 23, 2019

match is now treated like an alphabetic operator, it can be appear infix as
well as after ..

Motivation given in https://contributors.scala-lang.org/t/pre-sip-demote-match-keyword-to-a-method/2137/36?u=odersky

 - A match usually has more than one case anyway
 - That way, we increase the precedence of `match`, since
   what follows is always atomic.
`match` is treated like an alphabetic operator, can be appear infix as
well as after `.`.

Change the `inline` syntax from
```
inline if ...
inline s match ...
```
to
```
if inline ...
s match inline ...
```
this makes it work better with the new rules for `match`.
The syntax is no longer supported
Better not to mix up to syntax changes in one PR. Also, we might prefer inline match and
inline if in the end.
@odersky
Copy link
Contributor Author

odersky commented Nov 24, 2019

Best reviewed by looking at changed files directly, since there was a bit of going back of forth on the way.

@lihaoyi
Copy link
Contributor

lihaoyi commented Nov 25, 2019

Since match now behaves for all intents and purposes like a method call, are we going to demote it from a keyword to an intrinsic method the same way eq, ne, ==, etc. are? That also means you could foo match f where f is a partial/total function, which is something you cannot currently do. Also foo.match _ to eta-expand a function value.

These are all downstream changes that should be called out as a result of this syntax update

Otherwise it would be weird if match was the only keyword that you could use with or without a preceding .

@nafg
Copy link

nafg commented Nov 25, 2019 via email

@odersky
Copy link
Contributor Author

odersky commented Nov 25, 2019

Making match behave more like a method call is an option. But match will have to stay a reserved word in any case. It is used in a special way in match types and inline matches, neither of which can be expressed as simple method calls. So that weakens the case of making it a method, since it would not be a clean abstraction.

@martijnhoekstra
Copy link
Contributor

Making match behave more like a method call is an option. But match will have to stay a reserved word in any case. It is used in a special way in match types and inline matches, neither of which can be expressed as simple method calls. So that weakens the case of making it a method, since it would not be a clean abstraction.

which IMO is exactly the reason it shouldn't look like a method either.

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

case _ => true
}
then "nonempty"
else "empty"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear the selection may break the regularity of Scala syntax. It seems the use case is not important enough to compensate for the loss of regularity.

@odersky odersky merged commit 4adc435 into scala:master Nov 29, 2019
@odersky odersky deleted the change-match-syntax branch November 29, 2019 21:46

```scala
if xsDefined
&& xs.match {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that's why they call it "dotty".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants