Updated patterns-in-switch doc

forax at univ-mlv.fr forax at univ-mlv.fr
Sun Sep 13 18:30:34 UTC 2020

> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Dimanche 13 Septembre 2020 15:53:18
> Objet: Re: Updated patterns-in-switch doc

>> if we don't have constant pattern, it may also means that the type of a bound
>> variables can be implicit too.
>> i.e. case Point(x, y) having the same meaning as case Point(var x, var y) like
>> with lambdas.

> I don’t quite get the leap from “no constant patterns” to changing the syntax of
> deconstruction patterns, but in any case, we definitely don’t want this (and in
> fact, for the same reasons cited in the section on constant patterns, and
> others.)

if case Point(x, y) can not mean instanceof Point p where p.x == x && p.y == y, then case Point(x, y) can have the same meaning has a lambda (x, y), introducing two fresh variables x and y. 

> I don’t want people wondering whether `foo(x)` is an invocation of a method or a
> pattern. One of the problems with the obvious denotation of constant patterns
> is that `foo(0)` looks like an invocation with zero. With a variable, it is
> worse.

> Further, allowing `Point(x,y)` as a pattern would allow variables to be declared
> without anything that even looks like a variable declaration! Many people are
> already disturbed by the idea that variables can now be declared from within
> expressions; without an `int x` or `var x` to at least have a declaration to
> point to, it will be untenable.

Do you think that the way we declare lambdas is untenable ? 
Because with a lambda, we are introducing fresh variables without an explicit type or a var, you can use an explicit type or a var but you don't have to, 
and while i agree that the lambda syntax takes a little time to adjust when you are not familiar with it, i don't see people still struggling with that syntax in the long term. 

>> is not valid anymore and should be written like this
>> int c = ...
>> switch(getFoo()) {
>> case Foo(x) where x == c: ...
>> }

> No, it should be written

> case Foo(var x) where x == c:

see above. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20200913/0b21a815/attachment.htm>

More information about the amber-spec-experts mailing list