Array patterns (and varargs patterns)
John Rose
john.r.rose at oracle.com
Sat Sep 10 00:45:16 UTC 2022
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.
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/20220909/e92525ed/attachment-0001.htm>
More information about the amber-spec-observers
mailing list