unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#35869: [PATCH] `cl-member' and `cl-assoc' do not work for bignums
@ 2019-05-23 16:01 Mattias Engdegård
  2019-06-02  1:15 ` Paul Eggert
  0 siblings, 1 reply; 3+ messages in thread
From: Mattias Engdegård @ 2019-05-23 16:01 UTC (permalink / raw)
  To: 35869

[-- Attachment #1: Type: text/plain, Size: 136 bytes --]

(cl-member (ash 1 100) (list (ash 1 100))) => nil
(cl-assoc (ash 1 100) (list (cons (ash 1 100) t))) => nil

Suggested patch attached.


[-- Attachment #2: 0001-Fix-cl-member-and-cl-assoc-for-bignums.patch --]
[-- Type: application/octet-stream, Size: 2241 bytes --]

From 6313fdb00b13246305be0218452afefe9e05432c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Thu, 23 May 2019 17:54:58 +0200
Subject: [PATCH] Fix `cl-member' and `cl-assoc' for bignums

* lisp/emacs-lisp/cl-seq.el (cl-member, cl-assoc): Work with bignums.
* test/lisp/emacs-lisp/cl-seq-tests.el (cl-seq-bignum-eql): New.
---
 lisp/emacs-lisp/cl-seq.el            | 6 ++----
 test/lisp/emacs-lisp/cl-seq-tests.el | 8 ++++++++
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/lisp/emacs-lisp/cl-seq.el b/lisp/emacs-lisp/cl-seq.el
index 3eb6ea16da..86a73e1997 100644
--- a/lisp/emacs-lisp/cl-seq.el
+++ b/lisp/emacs-lisp/cl-seq.el
@@ -703,9 +703,7 @@ cl-member
 	(while (and cl-list (not (cl--check-test cl-item (car cl-list))))
 	  (setq cl-list (cdr cl-list)))
 	cl-list)
-    (if (and (numberp cl-item) (not (integerp cl-item)))
-	(member cl-item cl-list)
-      (memq cl-item cl-list))))
+    (memql cl-item cl-list)))
 (autoload 'cl--compiler-macro-member "cl-macs")
 
 ;;;###autoload
@@ -744,7 +742,7 @@ cl-assoc
 			(not (cl--check-test cl-item (car (car cl-alist))))))
 	  (setq cl-alist (cdr cl-alist)))
 	(and cl-alist (car cl-alist)))
-    (if (and (numberp cl-item) (not (integerp cl-item)))
+    (if (numberp cl-item)
 	(assoc cl-item cl-alist)
       (assq cl-item cl-alist))))
 (autoload 'cl--compiler-macro-assoc "cl-macs")
diff --git a/test/lisp/emacs-lisp/cl-seq-tests.el b/test/lisp/emacs-lisp/cl-seq-tests.el
index 86288e99ca..6515eee9f2 100644
--- a/test/lisp/emacs-lisp/cl-seq-tests.el
+++ b/test/lisp/emacs-lisp/cl-seq-tests.el
@@ -302,6 +302,14 @@ cl-seq--with-side-effects
     (should (equal '(2 8) (last (cl-replace list list2) 2)))
     (should (equal '(1 1) (last (cl-fill list 1) 2)))))
 
+(ert-deftest cl-seq-bignum-eql ()
+  (let ((x (+ most-positive-fixnum 1))
+        (y (+ most-positive-fixnum 1)))
+    (let ((l (list y)))
+      (should (eq (cl-member x l) l)))
+    (let ((a (list (cons y 1) (cons 2 y))))
+      (should (eq (cl-assoc x a) (car a)))
+      (should (eq (cl-rassoc x a) (cadr a))))))
 
 (provide 'cl-seq-tests)
 ;;; cl-seq-tests.el ends here
-- 
2.20.1 (Apple Git-117)


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#35869: [PATCH] `cl-member' and `cl-assoc' do not work for bignums
  2019-05-23 16:01 bug#35869: [PATCH] `cl-member' and `cl-assoc' do not work for bignums Mattias Engdegård
@ 2019-06-02  1:15 ` Paul Eggert
  2019-06-02 13:05   ` Mattias Engdegård
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Eggert @ 2019-06-02  1:15 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: 35869-done

[-- Attachment #1: Type: text/plain, Size: 154 bytes --]

Thanks, I installed that into the master branch, along with the attached minor 
tuneup to restore some of the optimization that was in the original code.

[-- Attachment #2: 0001-Tune-cl-assoc.patch --]
[-- Type: text/x-patch, Size: 855 bytes --]

From 1fd7d5086205852f1433e5042ca4efc1d50b1996 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 1 Jun 2019 18:12:31 -0700
Subject: [PATCH] Tune cl-assoc

* lisp/emacs-lisp/cl-seq.el (cl-assoc):	Use assq for fixnums.
---
 lisp/emacs-lisp/cl-seq.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/cl-seq.el b/lisp/emacs-lisp/cl-seq.el
index 86a73e1997..87c02a6b54 100644
--- a/lisp/emacs-lisp/cl-seq.el
+++ b/lisp/emacs-lisp/cl-seq.el
@@ -742,7 +742,7 @@ cl-assoc
 			(not (cl--check-test cl-item (car (car cl-alist))))))
 	  (setq cl-alist (cdr cl-alist)))
 	(and cl-alist (car cl-alist)))
-    (if (numberp cl-item)
+    (if (and (numberp cl-item) (not (fixnump cl-item)))
 	(assoc cl-item cl-alist)
       (assq cl-item cl-alist))))
 (autoload 'cl--compiler-macro-assoc "cl-macs")
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#35869: [PATCH] `cl-member' and `cl-assoc' do not work for bignums
  2019-06-02  1:15 ` Paul Eggert
@ 2019-06-02 13:05   ` Mattias Engdegård
  0 siblings, 0 replies; 3+ messages in thread
From: Mattias Engdegård @ 2019-06-02 13:05 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 35869-done

2 juni 2019 kl. 03.15 skrev Paul Eggert <eggert@cs.ucla.edu>:
> 
> Thanks, I installed that into the master branch, along with the attached minor tuneup to restore some of the optimization that was in the original code.

A good improvement, and thank you!







^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-02 13:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-23 16:01 bug#35869: [PATCH] `cl-member' and `cl-assoc' do not work for bignums Mattias Engdegård
2019-06-02  1:15 ` Paul Eggert
2019-06-02 13:05   ` Mattias Engdegård

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).