From: Pip Cet <pipcet@gmail.com>
To: Philipp Stephani <p.stephani2@gmail.com>
Cc: 43100@debbugs.gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#43100: 28.0.50; pcase not binding variables conditionally
Date: Sat, 29 Aug 2020 14:27:51 +0000 [thread overview]
Message-ID: <CAOqdjBdHzW4M+f_Jc5RONd25BJ6DKcYNo3jAYZB4kifDti_yRQ@mail.gmail.com> (raw)
In-Reply-To: <CAArVCkTPrDJoPXw+s5qzHqwygSut25E-eKXp+vDzp0-E+6n1PA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1739 bytes --]
On Sat, Aug 29, 2020 at 12:01 PM Philipp Stephani
<p.stephani2@gmail.com> wrote:
> Am Sa., 29. Aug. 2020 um 11:42 Uhr schrieb Pip Cet <pipcet@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.
[-- Attachment #2: 0001-Complain-about-in-backquote-pcase-patterns.patch --]
[-- Type: text/x-patch, Size: 810 bytes --]
From c52708d92dec4a6d7810d634dd4ff23a2cbca1ec Mon Sep 17 00:00:00 2001
From: Pip Cet <pipcet@gmail.com>
Date: Sat, 29 Aug 2020 14:21:29 +0000
Subject: [PATCH] Complain about ,@ in backquote pcase patterns
* lisp/emacs-lisp/pcase.el (\`): Complain upon encountering \,@ in
backquote pcase patterns.
---
lisp/emacs-lisp/pcase.el | 1 +
1 file changed, 1 insertion(+)
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el
index a8ce23284c..642ff0f73a 100644
--- a/lisp/emacs-lisp/pcase.el
+++ b/lisp/emacs-lisp/pcase.el
@@ -971,6 +971,7 @@ \`
(declare (debug (pcase-QPAT)))
(cond
((eq (car-safe qpat) '\,) (cadr qpat))
+ ((eq (car-safe qpat) '\,@) (error "sublist matching not supported"))
((vectorp qpat)
`(and (pred vectorp)
(app length ,(length qpat))
--
2.28.0
next prev parent reply other threads:[~2020-08-29 14:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-29 9:41 bug#43100: 28.0.50; pcase not binding variables conditionally Pip Cet
2020-08-29 12:01 ` Philipp Stephani
2020-08-29 14:27 ` Pip Cet [this message]
2020-08-29 16:06 ` Stefan Monnier
2020-08-30 16:21 ` Pip Cet
2020-08-30 18:07 ` Stefan Monnier
2020-08-31 19:32 ` Pip Cet
2020-09-01 3:12 ` Stefan Monnier
2020-09-02 8:38 ` Pip Cet
2020-09-02 14:16 ` Stefan Monnier
2020-09-05 14:36 ` Pip Cet
2020-09-05 16:52 ` Stefan Monnier
2021-03-02 13:38 ` Pip Cet
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAOqdjBdHzW4M+f_Jc5RONd25BJ6DKcYNo3jAYZB4kifDti_yRQ@mail.gmail.com \
--to=pipcet@gmail.com \
--cc=43100@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=p.stephani2@gmail.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).