Compact deconstruction patterns
Matthias Perktold
tias251 at gmail.com
Tue Mar 3 09:00:19 UTC 2020
According to
https://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html, the
current proposal is to allow to ways of using records as deconstruction
patterns:
1) With nested type patterns: case AddNode(Node left, Node right)) -> ...
2) With nested var patterns: case AddNode(var left, var right)) -> ...
I was wondering whether it could make sense to allow to leave out var:
case AddNode(left, right)) -> ...
This would be especially convenient for nested record patterns.
Compare
case Line(Point(var x0, var y0), Point(var x1, var y1)) -> ...
with
case Line(Point(x0, y0), Point(x1, y1)) -> ...
The consequence would be that the syntax rules for the innermost patterns
would more closely resemble the ones for lambda parameters rather than local
variables.
Note that, there is no risk of ambiguity.
Since it appears right after case, it's clear from the context that the
whole expression is used as a pattern.
The same holds for instanceof patterns.
Now I'm sure this idea has already crossed your mind.
Did you reject it for any particular reason?
Or do you simply want to wait until you are really sure this is something
you actually want?
I realize this can be added any time in a future release.
Thanks,
Matthias
More information about the amber-dev
mailing list