Question about Array Patterns
Brian Goetz
brian.goetz at oracle.com
Tue Feb 3 06:34:09 UTC 2026
I invite you to think about how such a thing might be implemented, and what arrays are for, and the question sort of answers itself.
The built-in patterns are about unpacking: recovering type information, unpacking records into their components, unpacking arrays into their contents. Asking whether an array contains exactly these elements, or even asking that question about a prefix of the elements, is an unpacking. Searching an array, as would be required by a wild card in the beginning or middle, is valid things to want to do, but it’s not unpacking. (And the cost model would be deceptive.)
Arrays are a low level, built-in feature of the language, not a database to be queried.
Sent from my iPad
On Feb 3, 2026, at 1:01 AM, David Alayachew <davidalayachew at gmail.com> wrote:
Hello @amber-dev<mailto:amber-dev at openjdk.org>,
I was a little surprised that I didn't notice this until now, but when re-reading Brian's Array Patterns write-up<https://mail.openjdk.org/pipermail/amber-spec-observers/2022-September/003635.html>, I realized that my brain auto-completed something that wasn't actually there.
In the write-up, there is only the concept of a prefix match or an exact match. But what about a suffix match? Or a "somewhere-in-the-center" match?
The original proposal for Array Patterns (that preceded this one) had the "..." syntax, which I mentally auto-completed to be "0 or more elements". Maybe that was a mistake on my part too.
Anyways, could I get some clarification? Is that intentionally unspecified for now, pending further thought? Or is that something that will be handled else where?
And by all means, what is there, I like. It's just that the message calls itself Array Patterns, so my thought is that it would cover all the possible types of matches one might want to do on an array.
Thank you for your time and help.
David Alayachew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20260203/77f9d1aa/attachment-0001.htm>
More information about the amber-dev
mailing list