On Wed, Dec 7, 2022, at 9:50 PM, Steven Ganz wrote:
> On Tuesday, December 6, 2022, at 12:30:19 AM, Aaron W. Hsu wrote:
>> I think the question arises when you draw an equivalency from the following chain:
>>
>> (<pat> . <id>) ←→ (<pat> <id> <ellipsis>)
>> =>
>> (<pat> <ellipsis> . <id>) ←→ (<pat> <ellipsis> <id> <ellipsis>)
> The last pattern is invalid because it has two ellipses as elements of
> the same list, right?
Yes, it is illegal, and that was the point that Chris was making in his original email. If such equivalencies hold, then it leads to an equivalence that is known to be illegal in the report. Chris' conclusion, as I understand it, is that this must imply that the patterns described are buggy. My alternative interpretation is that the equivalencies are in fact not true.
> Looking at it closely now. the report seems both confusing and wrong
> there, in using the same variable *n* for both the list expression
> length and the index of the last pattern element before the dot, and
> similarly reusing *m*.
My argument is that these are not in fact wrong. Assuming that a list has /n/ elements (not including the object in the final CDR), then there are /n/ CDRs, and the use of the same /n/ in both cases is intentional to bound them to the same value.
> Anyway, back on topic, I think the "and final" was unintentional and
> should be removed. It is the final cdr of the pattern, but not
> necessarily of the list.
I think it was intentional and that this is in fact meant to speak of the final CDR of the list, not of the pattern. The combination of the use of /n/ in reference to the length of /E/ as well as the use of the term final is a double emphasis on the position of /P_x/.
> Otherwise, we'd have to say that (x y ... . z) can't match (8 7 8),
> because the final cdr of the latter is ().
It does in fact match (8 7 8) and z is in fact (), as the final CDR. That's how I read it.
> I think we want the final cdr of the pattern to be able to reach into
> at least a proper list, if not an improper one.
Rather, I think the intention was that the final piece would either be () or the improper list's final CDR value. This allows you to match all of the elements of an improper or proper list using the same pattern and distinguishing one from the other reliably.
> That would still leave the question of whether the specification should
> enforce any of the multiple correct matchings (affecting the resulting
> bindings). I've been assuming a particular "greedy" solution of <pat>
> <ellipsis> matching as much as possible, but "possible" here would need
> to be carefully defined to allow for saving list elements that could
> otherwise match for necessary subsequent pattern elements, and we
> should probably avoid the "greedy" terminology in distinguishing this
> from any other non-backtracking solutions.
I think Chris' original assertions that a given pattern should have a single canonical and correct match without backtracking or ambiguity is correct. I don't think the pattern, as defined in the report, is intended to admit ambiguity as to the way in which the pattern is matched, and that the "greedy" match is in fact the one that was intended, with the final CDR matching the final /P_x/ pattern, which, with a proper list, will always be ().