From: Michael Heerdegen <michael_heerdegen@web.de>
To: hokomo <hokomo@airmail.cc>
Cc: 59887@debbugs.gnu.org
Subject: bug#59887: pcase vs. pcase-let: Underscore in backquote-style patterns
Date: Fri, 09 Dec 2022 03:57:31 +0100 [thread overview]
Message-ID: <87edt9nv1g.fsf@web.de> (raw)
In-Reply-To: <87sfhrqgxw.fsf@airmail.cc> (hokomo@airmail.cc's message of "Wed, 07 Dec 2022 17:28:57 +0100")
hokomo <hokomo@airmail.cc> writes:
> However, pcase-let is less strict about this, producing the same
> result with or without the comma:
>
> (pcase-let ((`(1 _ ,x) '(1 2 3)))
> x)
>
> ;; => 3
>
> (pcase-let ((`(1 ,_ ,x) '(1 2 3)))
> x)
>
> ;; => 3
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.
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 think that matching a literal underscore symbol is rare enough that
> the ideal behavior would probably be for an underscore within a
> backquote template to be treated as a wildcard whenever it appears
> literally (e.g., `(1 _)) or unquoted (e.g., `(1 ,_)). However, as soon
> as explicitly quoted (e.g., `(1 ,'_)), it should be treated as a match
> for a literal underscore symbol.
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.
Michael.
next prev parent reply other threads:[~2022-12-09 2:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-07 16:28 bug#59887: pcase vs. pcase-let: Underscore in backquote-style patterns hokomo
2022-12-09 2:57 ` Michael Heerdegen [this message]
2022-12-12 2:50 ` Michael Heerdegen
2022-12-12 18:26 ` hokomo
2022-12-13 1:17 ` Michael Heerdegen
2022-12-13 1:19 ` hokomo
2022-12-13 2:21 ` Michael Heerdegen
2022-12-13 2:26 ` hokomo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87edt9nv1g.fsf@web.de \
--to=michael_heerdegen@web.de \
--cc=59887@debbugs.gnu.org \
--cc=hokomo@airmail.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.