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
Message #8 received at 71503 <at> debbugs.gnu.org (full text, mbox):
Mekeor Melire <mekeor <at> posteo.de> writes:
> 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?
The difference is that pcase-lambda doesn't do case-distinction, but
just pattern matching/destruncting. So if the pattern-matching fails,
then the variable is just not bound, instead of the entire expression
falling back to returning no value/nil. I am guessing you wanted to
have something like Scheme's `case-lambda'[0]? Or we could clarify this
point in the docstring.
> In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
> 3.24.41, cairo version 1.16.0).
[0] https://index.scheme.org/filterset/r7rs_small/%28scheme%2520case-lambda%29/case-lambda
--
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.