Subject: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly

From: Ihor Radchenko <[email-masked]>
Date: Tue, 16 Jan 2024 18:43:45 +0000

Jim Porter <[email-masked]> writes:

> This isn't an issue with 'pcase-dolist', but rather a known/intentional 
> limitation of 'pcase-let':
>
> (pcase-let ((`(,(and (pred stringp) a) .
>                 ,(and (pred stringp) b))
>               '("TODO")))
>    (warn "%S :: %S" a b))
>    -> Warning (emacs): "TODO" :: nil
>
> The 'pcase-let' docstring says this:
>
>> Each EXP should match (i.e. be of compatible structure) to its
>> respective PATTERN; a mismatch may signal an error or may go
>> undetected, binding variables to arbitrary values, such as nil.
>
> I do think we should fix it somehow though. This behavior is extremely 
> confusing, and as much as I'm a fan of 'pcase', I'm emphatically *not* a 
> fan of how this part works.

Not sure about pcase-let, but pcase-dolist specifically may be
simplified not to use pcase-let:

(if (pcase--trivial-upat-p (car spec))
      `(dolist ,spec ,@body)
    (let ((tmpvar (gensym "x")))
      `(dolist (,tmpvar ,@(cdr spec))
         (pcase ,tmpvar (,(car spec) ,@body)))))

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>