bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#59887: pcase vs. pcase-let: Underscore in backquote-style patterns


From: hokomo
Subject: bug#59887: pcase vs. pcase-let: Underscore in backquote-style patterns
Date: Mon, 12 Dec 2022 19:26:28 +0100
User-agent: mu4e 1.8.9; emacs 28.2


Note this part of the `pcase-let' documentation string:

| Each EXP should match (i.e. be of compatible structure) to its
| respective PATTERN; a mismatch may signal an error or may go
| undetected, binding variables to arbitrary values, such as nil.

Your first case is invalid because the pattern doesn't match the value.
Here it goes undetected and bindings get established.

I see! That clarifies the behavior I was seeing.

This behavior is not perfect, but AFAIR it has been preferred over the
less efficient code that better checks would mean.  So it's the
programmer's task to use only matching patterns. This is not really a restriction because `pcase-let' is intended to create bindings, not for
testing whether a pattern matches some value.

I suppose that's a fair tradeoff.

This idea had been discussed in the past. It had some votes but it had been decided not to implement such a feature because it would not really fit into the existing semantics, just for the sake of leaving out one
",".  So I'm afraid I don't think we will change this.

Right, it doesn't seem like such a huge win now that I understand that the behavior of pcase-let was according to its specification and there was no inconsistency to begin with. It would maybe make the code a little bit easier to read in certain cases, but I can see your point.

I think the current behavior can be understood and explained from the documentation quite well. If you can point to something concrete
missing, please elaborate, and we can reopen this report.

Your quote above made everything clear, but I completely missed it since I was reading the Emacs Lisp manual's explanation [1] rather than pcase-let's docstring. Maybe it would be beneficial to include the above quote in the manual as well.

[1] <https://www.gnu.org/software/emacs/manual/html_node/elisp/Destructuring-with-pcase-Patterns.html>

Thanks!

hokomo





reply via email to

[Prev in Thread] Current Thread [Next in Thread]