<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body><div style="font-family: sans-serif;"><div class="markdown" style="white-space: normal;">
<p dir="auto">On 9 Sep 2022, at 9:09, <a href="mailto:forax@univ-mlv.fr" style="color: #3983C4;">forax@univ-mlv.fr</a> wrote:</p>
</div><div class="plaintext" style="white-space: normal;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; color: #777777;"><p dir="auto">----- Original Message -----
<br>
Here we want to extract the value into bindings/variables, that is not
<br>
what the varargs does, the varargs takes a bunch of value on stack and put them into an array.
<br>
Here we want the opposite operation of a varargs, the spread (or splat) operator that takes the argument from an array (or a collection ?) and put them on the stack.</p>
</blockquote></div>
<div class="markdown" style="white-space: normal;">
<p dir="auto">You are right that Brian’s proposal is not at its heart varargs, it is <em>array patterns</em> just as <em>array construction</em> are not equivalent to varargs, just a precursor to varargs.</p>
<p dir="auto">I think we need to get array patterns right first. Then we can move to whatever a fuller conception of varargs might look like “in the dual mirror”.</p>
<p dir="auto">In Brian’s architecture of patterns, every aggregator is matched as cleanly as possible with its dual pattern (which reverses data flows).</p>
<p dir="auto">There are actually two array construction expressions in Java today. (We could extend them with more varargs-flavored features to do slice/splat/spread/splice/whatever, but we don’t have them today!) The older expression takes a length and produces an uninitialized array. The slightly-less-old expression takes an initializer list <em>and refuses to take a length</em> and produces an initialized array, correctly sized.</p>
<p dir="auto">The most conservative application of Brian’s design principles would create, I think, <em>two distinct array patterns</em>, one for each kind of expression.</p>
<p dir="auto">Can the two patterns be merged? Yeah, maybe, but at the cost of disturbing the correspondence with array aggregation.</p>
<p dir="auto">And it may be that some of of the tricky questions about varargs go away if we restrict ourselves to just the two kinds of basic patterns that derive directly from today’s array creation expressions.</p>
<p dir="auto">Remember, patterns compose. If you have that rare need for both length and contents, use two patterns combined on the same array. There’s always a way to do that.</p>
<p dir="auto">If you want <em>some of the content</em> of an array to match a pattern, use a don’t care pattern. If you want length-polymorphism and element subpatterns (a match of one pattern to many lengths, with elements sprinkled around somehow) then we are beyond the bounds of today’s exercise, aren’t we?</p>
</div><div class="plaintext" style="white-space: normal;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; color: #777777;"><p dir="auto">If we have the pattern method Arrays.of()</p>
<p dir="auto">static <T> pattern (T...) of(T[] array) { // here it's a varargs
<br>
...
<br>
}</p>
<p dir="auto">and we call it using a named pattern
<br>
switch(array) {
<br>
case Arrays.of(/* insert a syntax here */) -> ...</p>
<p dir="auto">the syntax should extract some/all values of the array into one or several bindings.</p>
</blockquote></div>
<div class="markdown" style="white-space: normal;">
<p dir="auto">We’ll get there. Just not quite yet. One step at a time.</p>
<p dir="auto">I think it would be really neat to be able to “slice out” multi-element chunks of an array and bind them to pattern variables. Lisp folks have been enjoying this sort of thing basically forever. And <em>ignoring a range of elements</em> in a pattern is exactly equivalent to slicing them out and binding them to a don’t-care pattern, right?</p>
<p dir="auto">Confronted with such a feature, having thought about Brian’s principles, I think I would at the same time expect that there would be a dual array <em>construction</em> expression which would do the <em>mirror-opposite</em>. That is, it would “splice in” multi-element chunks, into a newly created array. The Lisp folks sometimes use the same notation for both splicing and slicing. (I’m thinking of backquote-comma-atsign, with and without some kind of pattern-bind.)</p>
<p dir="auto">Under Brian’s design principles, which I whole-heartedly agree with, I guess a slogan for array patterns might be: No slicing without splicing!</p>
</div></div></body>
</html>