<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="">
I would like to eventually come back for named record patterns, but I think we have to let the dust settle first.  <br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Apr 11, 2023, at 2:48 PM, Remi Forax <<a href="mailto:forax@univ-mlv.fr" class="">forax@univ-mlv.fr</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class=""><br class="Apple-interchange-newline">
<br class="">
</div>
<hr id="zwchr" data-marker="__DIVIDER__" class="">
<div data-marker="__HEADERS__" class="">
<blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;" class="">
<b class="">From:<span class="Apple-converted-space"> </span></b>"Robbe Pincket" <<a href="mailto:robbepincket@live.be" class="">robbepincket@live.be</a>><br class="">
<b class="">To:<span class="Apple-converted-space"> </span></b>"amber-dev" <<a href="mailto:amber-dev@openjdk.org" class="">amber-dev@openjdk.org</a>><br class="">
<b class="">Sent:<span class="Apple-converted-space"> </span></b>Monday, April 10, 2023 1:27:22 PM<br class="">
<b class="">Subject:<span class="Apple-converted-space"> </span></b>Named record patterns<br class="">
</blockquote>
</div>
<div class="">
<div data-marker="__QUOTED_TEXT__" class="">
<blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;" class="">
<div class="WordSection1" style="page: WordSection1;">
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">Hi all</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">I was wondering if named record patterns `o instanceof Pair(String left, String right) pair` are still on the table for the future or not. (Not sure if 'named' record pattern is the right name?)</span></div>
</div>
</blockquote>
<div class=""><br data-mce-bogus="1" class="">
</div>
<div class="">Let re-state what is the issue, currently there is no way to create a binding capturing the whole record instance, forcing people to transform the record pattern to a type pattern + when (see below).<br data-mce-bogus="1" class="">
</div>
<div class="">A previous preview was supporting this case using the syntax<br data-mce-bogus="1" class="">
</div>
<div class="">  case Pair(String left, String right) pair -> ...<br data-mce-bogus="1" class="">
</div>
<div class=""><br data-mce-bogus="1" class="">
</div>
<div class="">which did not work well in case someone want the binding to be also have an annotation or be declared final<br data-mce-bogus="1" class="">
</div>
<div class="">Here is the previous syntax with "final"<br data-mce-bogus="1" class="">
</div>
<div class="">  case final Pair(String left, String right) pair -> ...<br data-mce-bogus="1" class="">
</div>
<div class="">which is not very readable, the "final" being too far apart from the binding.<br data-mce-bogus="1" class="">
</div>
<div class=""><br data-mce-bogus="1" class="">
</div>
<div class="">One solution is to use a keyword like "as" to add a binding at the end of a record pattern (and perhaps other patterns ?)<br data-mce-bogus="1" class="">
</div>
<div class="">  case Pair(String left, String right) as final pair -> ...</div>
<div class="">which as the advantage of grouping the binding and its keyword at the cost of adding a new keyword.<br data-mce-bogus="1" class="">
</div>
<div class=""><br data-mce-bogus="1" class="">
</div>
<div class="">RĂ©mi<br data-mce-bogus="1" class="">
</div>
<div class=""><br data-mce-bogus="1" class="">
</div>
<blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;" class="">
<div class="WordSection1" style="page: WordSection1;">
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">IIRC they were shelfed due to the ambiguity that they could cause in this case, if there also exists a function `when`:</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">```</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">switch(o) {</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">    case Pair(String left, String right) when when (left == right) -> ...</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">}</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">```</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">It feels weird to me however that this feature was shelved just for this case, when a 'simple' rule could be introduced that a record pattern can't introduce a pattern variable with the name of a contextual keyword or at least not
 `when`.</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">Are there other reasons that record patterns can't introduce a variable that matches the whole pair anymore? It feels like it could be useful, even more so with JEP 443: Unnamed Patterns and Variables (Preview)</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">```</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">if (o instanceof ColoredPoint(Point(_, int y), _) cp && y > 0) {</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">    doAction(cp);</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">}</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">```</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">Instead of</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">```</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">if (o instanceof ColoredPoint(Point(int x, int y), Color c) && y > 0) {</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">    doAction(new ColoredPoint(new Point(x, y), c));</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">}</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">```</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">or this, if ColoredPoint can both hold `Point` and `Point3D`</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">```</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">if (o instanceof ColoredPoint cp && cp.point() instanceof Point(_, int y) && y > 0) {</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">    doAction(cp);</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">}</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">```</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">or if it can only hold `Point`</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">```</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">if (o instanceof ColoredPoint cp && cp.point().y() > 0) {</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">    doAction(cp);</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">}</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">```</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">Greetings</span></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<span lang="EN-US" class="">Robbe Pincket</span></div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</body>
</html>