GNU bug report logs - #75594
31.0.50; [FR]: Change equality test for Pcase non-linear patterns

Previous Next

Package: emacs;

Reported by: Eshel Yaron <me <at> eshelyaron.com>

Date: Wed, 15 Jan 2025 20:20:02 UTC

Severity: wishlist

Found in version 31.0.50

Full log


View this message in rfc822 format

From: Eshel Yaron <me <at> eshelyaron.com>
To: 75594 <at> debbugs.gnu.org
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, Michael Heerdegen <michael_heerdegen <at> web.de>
Subject: bug#75594: 31.0.50; [FR]: Change equality test for Pcase non-linear patterns
Date: Wed, 15 Jan 2025 21:19:09 +0100
Hi,

I want to use non-linear pcase patterns to match against source code
with el-search, and I find the existing equality test that Pcase
generates in such cases too strict (it uses eql, and I need equal).  

I can use (pred (equal foo)) patterns instead of just repeating foo,
but I'm generating the pattern programmatically and I'd rather avoid
special-casing the first foo occurrence.

What do you think about (1) switching to equal, or (2) allowing pcase
callers to specify the equality predicate?

I can imagine (1) having compatibility implications and (2) having
performance implications, but I don't have a good sense for how
significant these would be.

As one data point, the following diff seems to enable my use case,
without breaking Emacs bootstrap nor pcase-tests.el:

diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el
index a6a4751f49a..4f0fe6b64ab 100644
--- a/lisp/emacs-lisp/pcase.el
+++ b/lisp/emacs-lisp/pcase.el
@@ -1055,7 +1055,7 @@ pcase--u1
               (pcase--u1 matches code (cons (list upat sym) vars) rest)
             ;; Non-linear pattern.  Turn it into an `eq' test.
             (setcdr (cdr v) 'used)
-            (pcase--u1 (cons `(match ,sym . (pred (eql ,(cadr v))))
+            (pcase--u1 (cons `(match ,sym . (pred (equal ,(cadr v))))
                              matches)
                        code vars rest))))
        ((eq (car-safe upat) 'app)



Thanks,

Eshel




This bug report was last modified 151 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.