[External] : Re: Two new draft pattern matching JEPs
guy.steele at oracle.com
Wed Mar 10 00:50:58 UTC 2021
> On Mar 9, 2021, at 1:17 PM, forax at 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 Rectangle(Point(int x1, int y1), Point(int x2, int y2))
>> But perhaps in the current proposal one must write
>> case Rectangle(Point(int x1, int y1) & var p1, Point(int x2, int y2) & var p2)
>> or perhaps
>> case Rectangle(var p1 & Point(int x1, int y1), var p2 & Point(int x2, int y2))
>> In all of these cases, my argument is still the same: the simplest model is that
>> that deconstructor for Rectangle just supplies two values that are points, and
>> then the first point value is matched against the first sub pattern, and only
>> then is the second point value matched against the second subpattern. As a
>> result p2 and x2 and y2 do not yet have bindings or values while the first
>> sub-pattern is being matched.
> I think we agree here, i was just saying that for a deconstructor call you get all the bindings at the same time,
> so in the case there is two bindings, having two expressions that each one guard one binding is equivalent to have one guard that uses the two bindings.
> Obviously, when patterns are nested, you don't have access to all the bindings of all the patterns at once.
> Now, i don't think you have to use an & between patterns to provide a name, in my opinion, we should things in the other way
> case Rectangle(Point(int x1, int y1), Point(int x2, int y2))
> should be a simplified way to write
> case Rectangle(Point(int x1, int y1) _, Point(int x2, int y2) _)
> i.e. when destructuring, we don't provide a name for that binding (hence my use of '_')
> With that in mind, if you want to name the intermediary point, you can just write
> case Rectangle(Point(int x1, int y1) p1, Point(int x2, int y2) p2)
Yes, then I think we do agree here. We may have had a misunderstanding over language: I usually understand “binding” to mean the association of a value with a variable. I think that for a deconstructor you get all the _values_ at the same time, after which _bindings_ of variables to those values (or matching of sub patterns to those values) are established (or performed) sequentially. But this is a very delicate distinction that I am drawing.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the amber-spec-experts