Re: [External] : Re: Two new draft pattern matching JEPs

2021-03-09 Thread Guy Steele
> On Mar 9, 2021, at 1:17 PM, fo...@univ-mlv.fr wrote: >> . . . >> Now this example is not exactly analogous to your original, because we have >> not >> provided explicit variables for this purpose. I believe that in an earlier >> version of the design one would write >> >> case

Re: [External] : Re: Fwd: Two new draft pattern matching JEPs

2021-03-09 Thread John Rose
On Mar 9, 2021, at 12:23 PM, John Rose wrote: > > If switch refactors > to an if-chain, why then continue-switch would refactor to > continue-if, which turns out to branch to the next “else”, > if any. A bit more detail in case that was cryptic: switch (obj) { ... case P & G: … … }

Re: [External] : Re: Fwd: Two new draft pattern matching JEPs

2021-03-09 Thread John Rose
On Mar 5, 2021, at 8:29 AM, Brian Goetz wrote: > >> >> The one objection I still have to grobble is one I've raised before: it >> makes it hard to imagine ever representing disjunctions as guards. I always >> bring up stuff like >> >> switch (people) { >> case Pair(Person(String name1, int

Re: Two new draft pattern matching JEPs

2021-03-09 Thread forax
> De: "John Rose" > À: "Guy Steele" > Cc: "Remi Forax" , "Gavin Bierman" > , "amber-spec-experts" > > Envoyé: Samedi 6 Mars 2021 00:36:53 > Objet: Re: Two new draft pattern matching JEPs > On Mar 5, 2021, at 2:41

Re: Two new draft pattern matching JEPs

2021-03-09 Thread forax
- Mail original - > De: "Guy Steele" > À: "Remi Forax" > Cc: "Gavin Bierman" , "amber-spec-experts" > > Envoyé: Vendredi 5 Mars 2021 23:41:30 > Objet: Re: Two new draft pattern matching JEPs >> On Mar 3, 2021, at 7:5

Re: [External] : Re: Two new draft pattern matching JEPs

2021-03-09 Thread forax
- Mail original - > De: "Brian Goetz" > À: "Remi Forax" > Cc: "Gavin Bierman" , "amber-spec-experts" > > Envoyé: Jeudi 4 Mars 2021 17:28:05 > Objet: Re: [External] : Re: Two new draft pattern matching JEPs >> I want t

Re: [External] : Re: Two new draft pattern matching JEPs

2021-03-06 Thread Brian Goetz
On reflection, I think this is just something we have to trust users to do responsibly; use parentheses, newlines, and indentation to make their code clear. On 3/5/2021 7:11 PM, John Rose wrote: On Mar 4, 2021, at 8:28 AM, Brian Goetz > wrote: A lot of people

Re: Two new draft pattern matching JEPs

2021-03-06 Thread Brian Goetz
The “as” pattern which binds a value before doing more pattern matching Note that for all the patterns we have right now, there is no need: type patterns, record/deconstruction patterns, and array patterns all take an identifier (optional in the last two) which is the as-slot.  I believe

Re: [External] : Re: Two new draft pattern matching JEPs

2021-03-05 Thread John Rose
On Mar 4, 2021, at 8:28 AM, Brian Goetz wrote: > > A lot of people (initially, me included) would like to just interpret a > boolean expression as a pattern: > > case Foo(var x, var y) && x > y: ... > > I found that goal compelling, but as patterns get more complicated, this gets >

Re: Two new draft pattern matching JEPs

2021-03-05 Thread John Rose
I did careful pass over the docs and here are a couple more comments. You anticipated them at the end with the “here’s what else we might do” section. The “as” pattern which binds a value before doing more pattern matching on it should can be synthesized from “var” and “&”, as “P & var x”. The

Re: Two new draft pattern matching JEPs

2021-03-05 Thread John Rose
On Mar 5, 2021, at 2:41 PM, Guy Steele wrote: > >> because at the point where the pattern true(...) is evaluated, the Rectangle >> has already been destructured, obviously, we can ban this kind of patterns >> to try to conserve the left to right evaluation but the it will still leak >> in a

Re: Two new draft pattern matching JEPs

2021-03-05 Thread Brian Goetz
Complete agreement.  This amounts to a hidden laziness requirement that, while it might be possible to support it for built-in patterns, would present hideous translation challenges for nontrivial declared patterns. On 3/5/2021 5:41 PM, Guy Steele wrote: A compiler would likely optimize

Re: Two new draft pattern matching JEPs

2021-03-05 Thread Guy Steele
> On Mar 3, 2021, at 7:50 AM, Remi Forax wrote: > > - Mail original - >> De: "Gavin Bierman" >> À: "amber-spec-experts" >> Envoyé: Jeudi 18 Février 2021 13:33:20 >> Objet: Two new draft pattern matching JEPs > >> De

Re: [External] : Re: Fwd: Two new draft pattern matching JEPs

2021-03-05 Thread Brian Goetz
The one objection I still have to grobble is one I've raised before: it makes it hard to imagine ever representing disjunctions as guards. I always bring up stuff like switch (people) {   case Pair(Person(String name1, int age1), Person(String name2, int age2))     | age1 > age2 ->

Re: Two new draft pattern matching JEPs

2021-03-05 Thread Maurizio Cimadamore
Looks good - some comments below (I apologize if some of these have been raised elsewhere): ## Patterns in switch * In the general intro, maybe you could link this: https://bugs.openjdk.java.net/browse/JDK-4032356 or this: https://bugs.openjdk.java.net/browse/JDK-7127722 Which are all

Re: [External] : Re: Fwd: Two new draft pattern matching JEPs

2021-03-04 Thread Brian Goetz
be worrying about balancing the short term with the long. But, delaying further pattern matching progress until we have a full story for declared patterns seemed a bit extreme. So it's not that we missed that route -- indeed, that's the route that got us to the current position

Re: Fwd: Two new draft pattern matching JEPs

2021-03-04 Thread Alan Malloy
of value without overly constraining the remainder of the story, > but guards are an area where it is tempting to "borrow from the future." Of > course if we could do everything at once, we wouldn't be worrying about > balancing the short term with the long. But, delaying fu

Re: Fwd: Two new draft pattern matching JEPs

2021-03-04 Thread Brian Goetz
to the current position -- it's just that route was rejected as "would delay delivering real value now." Forwarded Message Subject:Re: Two new draft pattern matching JEPs Date: Thu, 4 Mar 2021 17:34:15 +0100 From: Victor Nazarov To: amber-spec-c

Fwd: Two new draft pattern matching JEPs

2021-03-04 Thread Brian Goetz
ted as "would delay delivering real value now." Forwarded Message -------- Subject: Re: Two new draft pattern matching JEPs Date: Thu, 4 Mar 2021 17:34:15 +0100 From: Victor Nazarov To: amber-spec-comme...@openjdk.java.net Hello Java experts, I've been following

Re: [External] : Re: Two new draft pattern matching JEPs

2021-03-04 Thread Brian Goetz
I want to separate the discussions about & between patterns and true()/false() aka mix pattern and expressions, because the later is a call for trouble for me, the former is just a question about adding a new pattern or not. I see true() and false() has an heresy because conceptually a

Re: [External] : Re: Two new draft pattern matching JEPs

2021-03-04 Thread forax
- Mail original - > De: "Gavin Bierman" > À: "Remi Forax" > Cc: "amber-spec-experts" > Envoyé: Jeudi 4 Mars 2021 15:27:41 > Objet: Re: [External] : Re: Two new draft pattern matching JEPs > Hi Remi, > > I know that Brian ha

Re: Two new draft pattern matching JEPs

2021-03-04 Thread forax
quot;amber-spec-experts" > Envoyé: Mercredi 3 Mars 2021 17:53:29 > Objet: Re: Two new draft pattern matching JEPs >> For a starter, at high level, the idea is to mix patterns and expressions >> (guards are boolean expressions), but at the same time, we have discussed >&g

Re: [External] : Re: Two new draft pattern matching JEPs

2021-03-04 Thread Gavin Bierman
Hi Remi, I know that Brian has already replied, but just to a couple of your points: > > The traditional approach for guards cleanly separate the pattern part from > the expression part > case Rectangle(Point x, Point y) if x > 0 && y > 0 > which makes far more sense IMO. > > The current

Re: [External] : Re: Two new draft pattern matching JEPs

2021-03-04 Thread Gavin Bierman
> On 3 Mar 2021, at 10:55, Remi Forax wrote: > > > I also found the code of the translation of > "printXCoordOfUpperLeftPointBeforePatterns" confusing, > because the local variable 'c' in this example is not related to the binding > 'c' in the pattern matching example. That’s a good point,

Re: Two new draft pattern matching JEPs

2021-03-03 Thread Brian Goetz
For a starter, at high level, the idea is to mix patterns and expressions (guards are boolean expressions), but at the same time, we have discussed several times to not allow constants inside patterns to make a clear distinction between patterns and expressions. We have a inconsistency

Re: Two new draft pattern matching JEPs

2021-03-03 Thread Brian Goetz
For me the section Pattern Matching and record classes is missing a discussion about the fact that even if the pattern uses a binding, the value of that binding is not accessed (so the corresponding record accessor is not called) until the binding is used at least once. As attractive as

Re: Two new draft pattern matching JEPs

2021-03-03 Thread Remi Forax
- Mail original - > De: "Gavin Bierman" > À: "amber-spec-experts" > Envoyé: Jeudi 18 Février 2021 13:33:20 > Objet: Two new draft pattern matching JEPs > Dear all, > [...] > > - Pattern Matching for switch: > https://bugs.openjdk.ja

Re: Two new draft pattern matching JEPs

2021-03-03 Thread Remi Forax
- Mail original - > De: "Gavin Bierman" > À: "amber-spec-experts" > Envoyé: Jeudi 18 Février 2021 13:33:20 > Objet: Two new draft pattern matching JEPs > Dear all, > > The next steps in adding pattern matching to Java are coming! I have draf

Re: Two new draft pattern matching JEPs

2021-02-18 Thread Tagir Valeev
Ah, indeed, thanks! Sorry for the noise then. On Thu, Feb 18, 2021 at 10:25 PM Brian Goetz wrote: > > > On 2/18/2021 7:52 AM, Tagir Valeev wrote: > > Hello! > > > > Thank you! > > > > There's a sample in Nested Record and Array Patterns draft: > > > > static void

Re: Two new draft pattern matching JEPs

2021-02-18 Thread Brian Goetz
On 2/18/2021 7:52 AM, Tagir Valeev wrote: Hello! Thank you! There's a sample in Nested Record and Array Patterns draft: static void printColorOfUpperLeftPoint(Object o) { if (o instanceof Rectangle(ColoredPoint ul, ColoredPoint lr)){ if (ul instanceof ColoredPoint(Point p,

Re: [External] : Re: Two new draft pattern matching JEPs

2021-02-18 Thread Gavin Bierman
Ha! I’ll change the example. Thanks, Gavin > On 18 Feb 2021, at 12:52, Tagir Valeev wrote: > > Hello! > > Thank you! > > There's a sample in Nested Record and Array Patterns draft: > > static void printColorOfUpperLeftPoint(Object o) { >if (o instanceof Rectangle(ColoredPoint ul,

Re: Two new draft pattern matching JEPs

2021-02-18 Thread Tagir Valeev
Hello! Thank you! There's a sample in Nested Record and Array Patterns draft: static void printColorOfUpperLeftPoint(Object o) { if (o instanceof Rectangle(ColoredPoint ul, ColoredPoint lr)){ if (ul instanceof ColoredPoint(Point p, Color c)) { System.out.println(c);

Two new draft pattern matching JEPs

2021-02-18 Thread Gavin Bierman
Dear all, The next steps in adding pattern matching to Java are coming! I have drafted two new JEPs: - Nested Record and Array Patterns: https://bugs.openjdk.java.net/browse/JDK-8260244 - Pattern Matching for switch: https://bugs.openjdk.java.net/browse/JDK-8213076 We split them up to try to