Array patterns (and varargs patterns)
Remi Forax
forax at univ-mlv.fr
Sat Sep 10 09:50:00 UTC 2022
> From: "John Rose" <john.r.rose at oracle.com>
> To: "Brian Goetz" <brian.goetz at oracle.com>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Sent: Saturday, September 10, 2022 2:45:16 AM
> Subject: Re: Array patterns (and varargs patterns)
> I was practicing that trick all morning!
> I agree that Foo[P] can be saved for later.
> In case it wasn’t clear in my previous message, I also think that splicey stuff
> like new Foo[]{ ...as, b, c, ...ds, e } and the corresponding slicey patterns
> can also be saved for later.
> In fact, the slice/splice stuff seems like it is best situated in a larger
> design exercise for “collection literals” whatever those are. Basically, that
> would be where Lisp’s backquote-comma get inherited by Java.
yes,
Rémi
> On 9 Sep 2022, at 17:16, Brian Goetz wrote:
>> John pulled a nice Jedi-mind-trick on me, and pointed out that we actually have
>> two creation expressions for arrays:
>> new Foo[n]
>> new Foo[] { a0, .., an }
>> and that if we are dualizing, then we should have these two patterns:
>> new Foo[] { P0, ..., Pn } // matches arrays of exactly length N
>> new Foo[P] // matches arrays whose length match P
>> but that neither
>> new Foo[] { P, Q, ... } // previous suggestion
>> nor
>> new Foo[L] { P, Q } // current suggestion
>> correspond to either of those, which suggests that we may have prematurely
>> optimized the pattern form. The rational consequence of this observation is to
>> do
>> new Foo[] { P0, ..., Pn } // matches arrays of exactly length N
>> now (which is also the basis of varargs patterns), and once we have constant
>> patterns (which are kind of required for the second form to be all that
>> useful), come back for `Foo[P]`.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-observers/attachments/20220910/91ef1a5f/attachment.htm>
More information about the amber-spec-observers
mailing list