Question about Array Patterns

David Alayachew davidalayachew at gmail.com
Tue Feb 3 07:22:47 UTC 2026


Thanks for the response.

Ok, so there's this term unpacking. And when it's used in reference in
patterns, it seems to mean the "export of contents of XYZ". Ok, cool. That
makes sense then why a full array load would be an unpacking, while a
suffix match is not. One must first unpack to search the tail, so that
makes sense. Probably better done as a library anyways, as a user-defined
pattern.

I guess I just don't see how a prefix match would be considered an
unpacking and not a query. What makes a prefix match an unpacking while a
suffix match is a query? I'm not seeing that detail yet. But I do see why a
center match is a query. That is unquestionably so.

You mentioned cost model, which is the only thing I can think of that might
differentiate it. I don't know the performance characteristics of getting
from the front of the array vs the back, so maybe that's the gap in my
knowledge that's preventing me from thinking this through? I wouldn't know
where to get that info, other than attempt (and likely fail) a benchmark in
JMH. But instinct (and informal tests) tells me they are equally as fast --
prefix vs suffix.


On Tue, Feb 3, 2026 at 1:34 AM Brian Goetz <brian.goetz at oracle.com> wrote:

> 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 <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/95aff2b5/attachment.htm>


More information about the amber-dev mailing list