GNU bug report logs -
#71503
30.0.50; pcase-lambda (with "and" and "guard") does not work as expected
Previous Next
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
[Message part 1 (text/plain, inline)]
Your message dated Sun, 04 Aug 2024 14:54:44 +0000
with message-id <87bk28z6bv.fsf <at> posteo.net>
and subject line Re: bug#71503: 30.0.50; pcase-lambda (with "and" and "guard") does not work as expected
has caused the debbugs.gnu.org bug report #71503,
regarding 30.0.50; pcase-lambda (with "and" and "guard") does not work as expected
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> 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)]
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).
[Message part 3 (message/rfc822, inline)]
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
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.