GNU bug report logs -
#43100
28.0.50; pcase not binding variables conditionally
Previous Next
Reported by: Pip Cet <pipcet <at> gmail.com>
Date: Sat, 29 Aug 2020 09:42:02 UTC
Severity: normal
Found in version 28.0.50
Done: Pip Cet <pipcet <at> gmail.com>
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 Tue, 2 Mar 2021 13:38:01 +0000
with message-id <CAOqdjBftgQkPayYBbHO-COuUhSXWy1bjHP9tYX4dGVUc4VMggA <at> mail.gmail.com>
and subject line Re: bug#43100: 28.0.50; pcase not binding variables conditionally
has caused the debbugs.gnu.org bug report #43100,
regarding 28.0.50; pcase not binding variables conditionally
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)
--
43100: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=43100
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
[Message part 3 (text/plain, inline)]
I'm having trouble with pcase's behavior.
(pcase "a"
((or (pred symbolp) name)
(let ((foo 'bar)) name)))
throws an error. It shouldn't. (Note that the dummy "let" is necessary
to force the pcase code generation to use a function call).
I believe the culprit is the code around this comment in pcase.el
;; If some of `vars' were not found in `prevvars', that's
;; OK it just means those vars aren't present in all
;; branches, so they can be used within the pattern
;; (e.g. by a `guard/let/pred') but not in the branch.
I believe that's incorrect: using the variable in a condition-case
should work, as should conditional shadowing of an existing binding,
as in this case:
(let ((name "default"))
(pcase "a"
((or (pred symbolp) name)
name)))
(which works), or this case:
(let ((name "default"))
(pcase "a"
((or (pred symbolp) name)
(let ((foo 'bar)) name))))
(which doesn't).
I believe the right fix is not to share code for the same branch if it
uses different variables, as in the attached patch. It's possible this
increases codegen complexity in some construed cases, but in practice
that shouldn't be a problem.
[0001-Allow-variable-bindings-to-differ-across-pcase-alter.patch (text/x-patch, attachment)]
[Message part 5 (message/rfc822, inline)]
On Sat, Aug 29, 2020 at 9:42 AM Pip Cet <pipcet <at> gmail.com> wrote:
>
> I'm having trouble with pcase's behavior.
>
> (pcase "a"
> ((or (pred symbolp) name)
> (let ((foo 'bar)) name)))
Stefan fixed this in 165353674e5fe7109ba9cbf526de0333902b7851, so I'm
closing this bug.
Pip
This bug report was last modified 4 years and 82 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.