From: Tino Calancha <tino.calancha@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 30202@debbugs.gnu.org, monnier@iro.umontreal.ca,
Tino Calancha <tino.calancha@gmail.com>
Subject: bug#30202: 27.0.50; Code refactoring on assq-delete-all assoc-delete-all
Date: Wed, 24 Jan 2018 12:10:42 +0900 (JST) [thread overview]
Message-ID: <alpine.DEB.2.20.1801241206170.24826@calancha-pc> (raw)
In-Reply-To: <83r2qgzhkz.fsf@gnu.org>
On Tue, 23 Jan 2018, Eli Zaretskii wrote:
> An even more minor nit: try to avoid starting a sentence with @var.
> In an Info manual, @var produces UPPER CASE, which looks OK at the
> beginning of a sentence; but in the printed manual, @var produces a
> lower-case word in slant typeface, which makes the sentence begin with
> a lower-case letter.
Excellent! Thank you!
Indeed I found very ugly when I wrote such sentence starting with @{var};
I couldn't find an alternative way to say what I wanted to say. You
summarized the point nicely.
Updated the patch (below).
I will push it by Sunday (4 days from now) if there is no more
activity in thi thread.
--8<-----------------------------cut here---------------start------------->8---
commit 55b82da7a7d0c1e016ef73ef46a7579fd9369cbf
Author: tino calancha <tino.calancha@gmail.com>
Date: Wed Jan 24 12:03:14 2018 +0900
Code refactoring
* lisp/subr.el (assoc-delete-all): Add optional arg TEST.
(assq-delete-all): Use assoc-delete-all.
* doc/lispref/lists.texi (Association Lists): Document
assoc-delete-all in the manual.
; * etc/NEWS: Add entry for assoc-delete-all
diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi
index 3e2dd13c70..761750eb20 100644
--- a/doc/lispref/lists.texi
+++ b/doc/lispref/lists.texi
@@ -1733,6 +1733,14 @@ Association Lists
@end example
@end defun
+@defun assoc-delete-all key alist &optional test
+This function is like @code{assq-delete-all} except that it accepts
+an optional argument @var{test}, a predicate function to compare the
+keys in @var{alist}. If omitted or @code{nil}, @var{test} defaults to
+@code{equal}. As @code{assq-delete-all}, this function often modifies
+the original list structure of @var{alist}.
+@end defun
+
@defun rassq-delete-all value alist
This function deletes from @var{alist} all the elements whose @sc{cdr}
is @code{eq} to @var{value}. It returns the shortened alist, and
diff --git a/etc/NEWS b/etc/NEWS
index d30f0b087c..c491777781 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -204,6 +204,9 @@ as new-style, bind the new variable 'force-new-style-backquotes' to t.
* Lisp Changes in Emacs 27.1
++++
+** New function assoc-delete-all.
+
** 'print-quoted' now defaults to t, so if you want to see
(quote x) instead of 'x you will have to bind it to nil where applicable.
diff --git a/lisp/subr.el b/lisp/subr.el
index 092850a44d..e7a0ffc5be 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -705,17 +705,19 @@ 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 assoc-delete-all (key alist &optional test)
+ "Delete from ALIST all elements whose car is KEY.
+Compare keys with TEST. Defaults to `equal'.
Return the modified alist.
Elements of ALIST that are not conses are ignored."
+ (unless test (setq test #'equal))
(while (and (consp (car alist))
- (equal (car (car alist)) key))
+ (funcall test (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 test (caar tail-cdr) key))
(setcdr tail (cdr tail-cdr))
(setq tail tail-cdr))))
alist)
@@ -724,16 +726,7 @@ assq-delete-all
"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)
+ (assoc-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---
next prev parent reply other threads:[~2018-01-24 3:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-22 5:24 bug#30202: 27.0.50; Code refactoring on assq-delete-all assoc-delete-all Tino Calancha
2018-01-22 13:17 ` 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 [this message]
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=alpine.DEB.2.20.1801241206170.24826@calancha-pc \
--to=tino.calancha@gmail.com \
--cc=30202@debbugs.gnu.org \
--cc=eliz@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).