GNU bug report logs - #30202
27.0.50; Code refactoring on assq-delete-all assoc-delete-all

Previous Next

Package: emacs;

Reported by: Tino Calancha <tino.calancha <at> gmail.com>

Date: Mon, 22 Jan 2018 05:26:01 UTC

Severity: wishlist

Found in version 27.0.50

Done: Tino Calancha <tino.calancha <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#30202: closed (27.0.50; Code refactoring on assq-delete-all
 assoc-delete-all)
Date: Sun, 28 Jan 2018 04:13:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Sun, 28 Jan 2018 13:12:42 +0900
with message-id <87y3kipqo5.fsf <at> gmail.com>
and subject line Re: bug#30202: 27.0.50; Code refactoring on assq-delete-all assoc-delete-all
has caused the debbugs.gnu.org bug report #30202,
regarding 27.0.50; Code refactoring on assq-delete-all assoc-delete-all
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
30202: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=30202
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Tino Calancha <tino.calancha <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 27.0.50; Code refactoring on assq-delete-all assoc-delete-all
Date: Mon, 22 Jan 2018 14:24:38 +0900
X-Debbugs-CC: monnier <at> iro.umontreal.ca
Severity: wishlist

Hi Stefan,

yesterday was added (how about to announce it in NEWS file?)
the new function `assoc-delete-all', which is pretty much
the same as `assq-delete-all' with `equal' instead of `eq'.

How do you think below patch?
IIUC, the byte compiler will carry the substitution
(funcall function foo bar)
into
(function foo bar)

so that compile code won't suffer the funcall overhead, right?

* `rassq-delete-all' is also very similar, maybe it could also join the
refactoring.

--8<-----------------------------cut here---------------start------------->8---
commit 11e4408e9f35d4da1cf07effda63354dde44d9a6
Author: tino calancha <tino.calancha <at> gmail.com>
Date:   Mon Jan 22 13:57:37 2018 +0900

    Code refactoring
    
    * lisp/subr.el (alist-delete-all): New defun extracted from
    assq-delete-all.
    (assoc-delete-all, assq-delete-all): Use it.

diff --git a/lisp/subr.el b/lisp/subr.el
index 092850a44d..d8286c0937 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -705,35 +705,33 @@ member-ignore-case
     (setq list (cdr list)))
   list)
 
-(defun assoc-delete-all (key alist)
-  "Delete from ALIST all elements whose car is `equal' to KEY.
+(defun alist-delete-all (key alist function)
+  "Delete from ALIST all elements whose car is KEY.
+Keys are compared with FUNCTION.
 Return the modified alist.
 Elements of ALIST that are not conses are ignored."
   (while (and (consp (car alist))
-	      (equal (car (car alist)) key))
+	      (funcall function (caar alist) key))
     (setq alist (cdr alist)))
   (let ((tail alist) tail-cdr)
     (while (setq tail-cdr (cdr tail))
       (if (and (consp (car tail-cdr))
-	       (equal (car (car tail-cdr)) key))
+	       (funcall function (caar tail-cdr) key))
 	  (setcdr tail (cdr tail-cdr))
 	(setq tail tail-cdr))))
   alist)
 
+(defun assoc-delete-all (key alist)
+  "Delete from ALIST all elements whose car is `equal' to KEY.
+Return the modified alist.
+Elements of ALIST that are not conses are ignored."
+  (alist-delete-all key alist #'equal))
+
 (defun assq-delete-all (key alist)
   "Delete from ALIST all elements whose car is `eq' to KEY.
 Return the modified alist.
 Elements of ALIST that are not conses are ignored."
-  (while (and (consp (car alist))
-	      (eq (car (car alist)) key))
-    (setq alist (cdr alist)))
-  (let ((tail alist) tail-cdr)
-    (while (setq tail-cdr (cdr tail))
-      (if (and (consp (car tail-cdr))
-	       (eq (car (car tail-cdr)) key))
-	  (setcdr tail (cdr tail-cdr))
-	(setq tail tail-cdr))))
-  alist)
+  (alist-delete-all key alist #'eq))
 
 (defun rassq-delete-all (value alist)
   "Delete from ALIST all elements whose cdr is `eq' to VALUE.

--8<-----------------------------cut here---------------end--------------->8---


In GNU Emacs 27.0.50 (build 13, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2018-01-22 built on calancha-pc
Repository revision: 9fd9d4cf63d96ba9748b9e89137575e386191c82


[Message part 3 (message/rfc822, inline)]
From: Tino Calancha <tino.calancha <at> gmail.com>
To: 30202-done <at> debbugs.gnu.org
Subject: Re: bug#30202: 27.0.50;
 Code refactoring on assq-delete-all assoc-delete-all
Date: Sun, 28 Jan 2018 13:12:42 +0900
Tino Calancha <tino.calancha <at> gmail.com> writes:

> Updated the patch (below).
> I will push it by Sunday (4 days from now) if there is no more
> activity in this thread.
Commited into master branch,
'Code refactoring assoc-delete-all assq-delete-all'
(9824885fabea53f8c4461d038f4c1edad1b8f591)


This bug report was last modified 7 years and 121 days ago.

Previous Next


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