unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: 30202@debbugs.gnu.org
Cc: monnier@iro.umontreal.ca
Subject: bug#30202: 27.0.50; Code refactoring on assq-delete-all assoc-delete-all
Date: Mon, 22 Jan 2018 14:24:38 +0900	[thread overview]
Message-ID: <87r2qilb3d.fsf@gmail.com> (raw)

X-Debbugs-CC: monnier@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@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





             reply	other threads:[~2018-01-22  5:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-22  5:24 Tino Calancha [this message]
2018-01-22 13:17 ` bug#30202: 27.0.50; Code refactoring on assq-delete-all assoc-delete-all Stefan Monnier
2018-01-22 15:04   ` Tino Calancha
2018-01-22 15:46 ` Eli Zaretskii
2018-01-23  0:02   ` Tino Calancha
2018-01-23 16:05     ` Eli Zaretskii
2018-01-24  3:10       ` Tino Calancha
2018-01-28  4:12         ` Tino Calancha

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=87r2qilb3d.fsf@gmail.com \
    --to=tino.calancha@gmail.com \
    --cc=30202@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).