GNU bug report logs -
#75594
31.0.50; [FR]: Change equality test for Pcase non-linear patterns
Previous Next
Full log
View this message in rfc822 format
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.