GNU bug report logs - #68509
30.0.50; pcase-dolist matches backquote pattern incorrectly

Previous Next

Package: emacs;

Reported by: Ihor Radchenko <yantar92 <at> posteo.net>

Date: Tue, 16 Jan 2024 15:06:01 UTC

Severity: normal

Found in version 30.0.50

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Ihor Radchenko <yantar92 <at> posteo.net>
Cc: Jim Porter <jporterbugs <at> gmail.com>, 68509 <at> debbugs.gnu.org
Subject: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly
Date: Mon, 19 Feb 2024 21:46:12 -0500
>> The difficulty in resolving this can be illustrated with the following
>> pattern:
>>
>>     `(a . ,b)
>>
>> This pattern leads to two tests: (consp VAL) and (eq 'a (car VAL)).
>> When destructuring, we want to throw away both tests (we want to throw
>> away most tests, except those needed to choose between two `or`
>> branches).
>>
>> We could decide to emit a warning because we silently skip
>> the `eq` test, which would help the coders understand that the pattern
>> doesn't do what they think.
>> But emitting that same warning because we silently skip the `consp` test
>> would be really annoying because rewriting the pattern to avoid this
>> is impractical.
>
> May you please elaborate how this example is related to destructuring
> from user perspective? It appears to me that you are talking about
> implementation details of `pcase', which are elusive to me.

I'm just reading aloud what the `(a . ,b) pattern means: it means "VAL
has to be a cons, and its car should be equal to `a`" (and in addition
to that, we'll extract the `cdr` and put it into the `b` variable).

We might want to warn the user that such a pattern in `pcase-let` and
`pcase-dolist` is probably an error because the `a` won't actually be
checked, so it will behave just like the `(,_ . ,b) pattern.

But warning the user that the `consp` check will also be dropped would
be annoying because it's not like the users can easily write a different
pattern that still behaves the same but does not imply such
a `consp` check.


        Stefan





This bug report was last modified 1 year and 113 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.