GNU bug report logs - #71503
30.0.50; pcase-lambda (with "and" and "guard") does not work as expected

Previous Next

Package: emacs;

Reported by: Mekeor Melire <mekeor <at> posteo.de>

Date: Wed, 12 Jun 2024 08:42:01 UTC

Severity: normal

Found in version 30.0.50

Done: Philip Kaludercic <philipk <at> posteo.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Mekeor Melire <mekeor <at> posteo.de>
Subject: bug#71503: closed (Re: bug#71503: 30.0.50; pcase-lambda (with
 "and" and "guard") does not work as expected)
Date: Sun, 04 Aug 2024 14:56:03 +0000
[Message part 1 (text/plain, inline)]
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 71503 <at> debbugs.gnu.org.

-- 
71503: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=71503
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Philip Kaludercic <philipk <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: mekeor <at> posteo.de, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 71503-done <at> debbugs.gnu.org
Subject: Re: bug#71503: 30.0.50; pcase-lambda (with "and" and "guard") does
 not work as expected
Date: Sun, 04 Aug 2024 14:54:44 +0000
Eli Zaretskii <eliz <at> gnu.org> 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 <monnier <at> iro.umontreal.ca>
>> Cc: Eli Zaretskii <eliz <at> gnu.org>,  mekeor <at> posteo.de,  71503 <at> debbugs.gnu.org
>> 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

[Message part 3 (message/rfc822, inline)]
From: Mekeor Melire <mekeor <at> posteo.de>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.0.50; pcase-lambda (with "and" and "guard") does not work as
 expected
Date: Wed, 12 Jun 2024 08:40:54 +0000
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).



This bug report was last modified 287 days ago.

Previous Next


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