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

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 04 Aug 2024 14:56:03 +0000

Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
71503: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=71503
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#71503: 30.0.50; pcase-lambda (with "and" and "guard") does not work as expected
From: Philip Kaludercic <[email-masked]>
To: Eli Zaretskii <[email-masked]>
Cc: [email-masked], Stefan Monnier <[email-masked]>, [email-masked]
Date: Sun, 04 Aug 2024 14:54:44 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Eli Zaretskii <[email-masked]> writes:

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

I've pushed the change in 0756f308 that Mekeor previously acknowledged
as fine.  Closing.

>> 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
>> 
>> 

-- 
	Philip Kaludercic on peregrine

Subject: 30.0.50; pcase-lambda (with "and" and "guard") does not work as expected
From: Mekeor Melire <[email-masked]>
To: [email-masked]
Date: Wed, 12 Jun 2024 08:40:54 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

I was expecting these two expressions to evaluate to the same value.
First, we call `pcase' on a value with a pattern involving `and' and
`guard':

    (pcase "value"
      ((and v (guard (string= "not-value" v))) v))
    ;; => nil

Second, let's use the same value and pattern, but this time using
`pcase-lambda':

    (funcall
      (pcase-lambda
        ((and v (guard (string= "not-value" v)))) v)
      "value")
    ;; => "value"

Am I missing something or is this a bug?

In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.41, cairo version 1.16.0).