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)]
On Sat, Aug 29, 2020 at 12:01 PM Philipp Stephani
<p.stephani2 <at> gmail.com> wrote:
> Am Sa., 29. Aug. 2020 um 11:42 Uhr schrieb Pip Cet <pipcet <at> gmail.com>:
> > I'm having trouble with pcase's behavior.
> >
> > (pcase "a"
> > ((or (pred symbolp) name)
> > (let ((foo 'bar)) name)))
> >
> > throws an error. It shouldn't.
>
> Isn't this case documented in the manual? The last section of
> https://www.gnu.org/software/emacs/manual/html_node/elisp/pcase-Macro.html
> states:
> "It makes no sense for each sub-pattern [in an `or' sequence] to
> let-bind a different set of symbols because the body forms have no way
> to distinguish which sub-pattern matched and choose among the
> different sets."
Thanks for pointing this out.
I disagree with what the documentation says there: it does make
perfect sense, to me, to conditionally shadow a (lexical) let binding
with a pcase-let one, and body forms will have no trouble in practice
distinguishing between the outer and the inner let-binding. The code
obviously attempts to handle this case, too, it just doesn't get it
perfectly right.
I agree and accept that pcase is very limited, and it probably always
will be, but I think those limitations shouldn't be entirely
arbitrary, and hitting them shouldn't cause silently malfunctioning
code but error messages.
Things like the behavior of
(pcase-let ((`(,a ,@b) (list 3 4)))
a)
just seem puzzling to me. There are good reasons not to implement
sublist matching (though I don't think those reasons are sufficient
not to have a simple implementation anyway), so an error message would
be acceptable, but the current implementation treats \,@ as an
ordinary symbol, which doesn't help anyone.
Sorry for complaining. Here's a patch.
[0001-Complain-about-in-backquote-pcase-patterns.patch (text/x-patch, attachment)]
This bug report was last modified 4 years and 83 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.