Subject: bug#71503: 30.0.50; pcase-lambda (with "and" and "guard") does not work as expected

From: Eli Zaretskii <[email-masked]>
Date: Sun, 04 Aug 2024 10:58:00 +0300

Ping!  can we please make progress with this issue, one way or
another?

> From: Stefan Monnier <[email-masked]>
> Cc: Eli Zaretskii <[email-masked]>,  [email-masked],  [email-masked]
> Date: Sun, 21 Jul 2024 09:51:04 -0400
> 
> > Another confusing behaviour that we should document is that in
> >
> > (let ((a nil))
> >   (funcall
> >    (pcase-lambda (a (and (guard a) b))
> >      (list a b))
> >    1 2))
> >
> > I would expect that the (guard a) would use the nil binding from the
> > `let' form, but instead it is ignored and b is bound to 2.  I am not
> > sure if this is related to the "destructing" point or not.
> 
> It most definitely is: the `guard` controls here whether the pattern
> matches or not, but since it's a destructuring match `pcase` takes it
> for granted that the pattern does match, so the guard is ignored.
> 
> What might be more confusing is the scoping, e.g.:
> 
>     (macroexpand '(pcase-lambda ((and (guard a) b) a) (FOO)))
> =>
>     #'(lambda (arg0 a) (pcase-let* (((and (guard a) b) arg0)) (FOO)))
> 
> so the `a` in the guard refers to the argument that follows rather than
> to a surrounding `a` binding.
> 
> 
>         Stefan
> 
>