<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Hi Tagir,
<div class=""><br class="">
</div>
<div class="">So it was a number of issues actually. First, there is a nasty ambiguity problem. Consider:</div>
<div class=""><br class="">
</div>
<div class=""><font face="Courier" class="">record R(){} <br class="">
switch(e) { <br class="">
case R() when when (true) -> ... <br class="">
... <br class="">
} </font><br class="">
<br class="">
The label could be parsed as either: <br class="">
<br class="">
<font face="Courier" class=""> case (R() when) when (true) -> <br class="">
</font><br class="">
or <br class="">
<br class="">
<font face="Courier" class=""> case (R()) when (when(true)) -> <br class="">
</font><br class="">
(where `<font face="Courier" class="">when</font>` is a static boolean method). <br class="">
<div class=""><br class="">
</div>
<div class="">There is another issue which is this variable declaration is the only one in the language that can’t be annotated or marked as `final` which feels like a design smell. None of the obvious solutions to this looked good. </div>
<div class=""><br class="">
</div>
<div class="">In most other languages with pattern matching they keep these two things - a destructing pattern and a naming pattern - separate. In both Haskell and Scala, they write `x@p` to “name” a pattern p as x. So that seems like a possibility. But for
now, we noted that in most cases you can rewrite pretty simply, e.g.</div>
<div class=""><br class="">
</div>
<div class=""><font face="Courier" class=""> case Point(var x, var y) when p.isVisible() -> </font></div>
<div class=""><br class="">
</div>
<div class="">can be rewritten:</div>
<div class=""><br class="">
</div>
<div class=""><font face="Courier" class=""> case Point p <br class="">
when p.isVisible() && p instanceof Point(var x, var y): …<br class="">
</font><br class="">
or if it was in an instanceof:<br class="">
<br class="">
<font face="Courier" class=""> if (x instanceof Point p && p.isVisible() && p instanceof Point(var x, var y)) { … }</font></div>
<div><br class="">
</div>
<div>Neither of these versions read too badly.</div>
<div><br class="">
</div>
<div>Thoughts?</div>
<div><br class="">
</div>
<div>Gavin</div>
<div><br class="">
</div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 3 Oct 2022, at 14:40, Tagir Valeev <<a href="mailto:amaembo@gmail.com" class="">amaembo@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">Hello!<br class="">
<br class="">
<blockquote type="cite" class="">Remove support for named record patterns.<br class="">
</blockquote>
<br class="">
This surprises me. Probably there was a discussion about the rationale<br class="">
behind this change? Could you please point me? Thanks.<br class="">
<br class="">
With best regards,<br class="">
Tagir Valeev<br class="">
<br class="">
On Mon, Oct 3, 2022 at 2:48 PM Gavin Bierman <<a href="mailto:gavin.bierman@oracle.com" class="">gavin.bierman@oracle.com</a>> wrote:<br class="">
<blockquote type="cite" class=""><br class="">
Dear all,<br class="">
<br class="">
The draft JEPs for the next preview of the Pattern Matching for switch and Record Patterns features are now available at:<br class="">
<br class="">
Pattern matching for switch: <a href="https://bugs.openjdk.org/browse/JDK-8294285" class="">
https://bugs.openjdk.org/browse/JDK-8294285</a><br class="">
Record Patterns: <a href="https://bugs.openjdk.org/browse/JDK-8294078" class="">https://bugs.openjdk.org/browse/JDK-8294078</a><br class="">
<br class="">
Comments welcomed!<br class="">
Gavin<br class="">
</blockquote>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>