From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#30202: 27.0.50; Code refactoring on assq-delete-all assoc-delete-all Date: Tue, 23 Jan 2018 09:02:12 +0900 (JST) Message-ID: References: <87r2qilb3d.fsf@gmail.com> <83lggprj4c.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1516665689 17168 195.159.176.226 (23 Jan 2018 00:01:29 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 23 Jan 2018 00:01:29 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Cc: 30202@debbugs.gnu.org, monnier@iro.umontreal.ca, Tino Calancha To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jan 23 01:01:24 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1edm1W-0003C4-Ty for geb-bug-gnu-emacs@m.gmane.org; Tue, 23 Jan 2018 01:01:11 +0100 Original-Received: from localhost ([::1]:47805 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edm3V-0001aY-Dc for geb-bug-gnu-emacs@m.gmane.org; Mon, 22 Jan 2018 19:03:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50621) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edm3N-0001a5-Uv for bug-gnu-emacs@gnu.org; Mon, 22 Jan 2018 19:03:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edm3K-0001GK-R6 for bug-gnu-emacs@gnu.org; Mon, 22 Jan 2018 19:03:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:59076) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edm3K-0001Fl-Ni for bug-gnu-emacs@gnu.org; Mon, 22 Jan 2018 19:03:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1edm3K-000417-A6 for bug-gnu-emacs@gnu.org; Mon, 22 Jan 2018 19:03:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 23 Jan 2018 00:03:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30202 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 30202-submit@debbugs.gnu.org id=B30202.151666574315383 (code B ref 30202); Tue, 23 Jan 2018 00:03:02 +0000 Original-Received: (at 30202) by debbugs.gnu.org; 23 Jan 2018 00:02:23 +0000 Original-Received: from localhost ([127.0.0.1]:38740 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1edm2h-000402-90 for submit@debbugs.gnu.org; Mon, 22 Jan 2018 19:02:23 -0500 Original-Received: from mail-pg0-f50.google.com ([74.125.83.50]:41859) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1edm2g-0003zq-Ao for 30202@debbugs.gnu.org; Mon, 22 Jan 2018 19:02:22 -0500 Original-Received: by mail-pg0-f50.google.com with SMTP id 136so8356136pgd.8 for <30202@debbugs.gnu.org>; Mon, 22 Jan 2018 16:02:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=D1QOkMyIBFAZ/LKkqsghnjY/9+LL+HopUQAM25iBd/g=; b=FoEBmqclrvJPv/4fjrzOclZFWzHByp/i50NFPm/WZfL0f+bUMGQLSeE4MHl3wmBpdg hN4IJJeS3e6LJjfpPppys6ulhzR7KcjQvaQWFKr0FVmOHOwm/nkUk+PVrQGqkOeqPmAY /D7lIoulx0ZivQ1pIuqb57ODKiM277FOFRrusHAx8tzfEQtT7DHIYX59p39i9a0pxVKB aeaU2jrOLRPu8/RnFsIzurMQZU7QkScBEAcQUmiMpDgMvVyO+1unchrg4U3icolUJnL1 g8i14lIL56gDP1jTSoWDObb9Od46tXmMcF5nC/RTwQYH9E7MiacqilIsaxnu3Tx/Trk/ RWag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=D1QOkMyIBFAZ/LKkqsghnjY/9+LL+HopUQAM25iBd/g=; b=YIsaDcYL+PQNhc8Z7vEqvj9ggi6JR1xc5k1y1OvzqCgVWkP8b4t7RxSFPo1nXEayq7 eHghPnJH5sKnV0Wtf+PiJcqbTKrVby+gn+PHbDd6IjaDA+W/CgtTNkQN4fCkrTYVtRO2 fXvSM0CGucOLqShIu8KIRJvVEOpXrmKoh4i3PN5qqTyOhWCWZU6jI3WvcQG3OrWG8fqV RwUnuCubNnGchzuTQBwZAPC/4baWESrmASv0YHZhaPsQg6How3aozEZXcFkABMu0VqOU yUJ7Rz+wX2UL++vdrS+YQgXZuPz6K/qS3SC2sQF4xV9hsqifAT95UUhN1y+/HP+h+9ug LagQ== X-Gm-Message-State: AKwxyte2UqwU75s44Jpb/w927CGMaxK+kGn/id3U83V8sIWUxwFWnkm4 CRrG9l9EHWpHx5ix64XoSow= X-Google-Smtp-Source: AH8x227w6qz8NjJHKvgmqSA0HeVgupQBjFSy6RktXxYQwYJxdzXwWrO8m5ddcy2enTCElx26XCOx8A== X-Received: by 10.101.76.14 with SMTP id u14mr7629262pgq.363.1516665736387; Mon, 22 Jan 2018 16:02:16 -0800 (PST) Original-Received: from calancha-pc (FL1-125-193-170-29.tky.mesh.ad.jp. [125.193.170.29]) by smtp.gmail.com with ESMTPSA id x8sm2070152pfk.123.2018.01.22.16.02.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jan 2018 16:02:15 -0800 (PST) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc In-Reply-To: <83lggprj4c.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:142406 Archived-At: On Mon, 22 Jan 2018, Eli Zaretskii wrote: >> From: Tino Calancha >> Date: Mon, 22 Jan 2018 14:24:38 +0900 >> Cc: monnier@iro.umontreal.ca >> >> yesterday was added (how about to announce it in NEWS file?) > > Please just add a NEWS entry if you find a missing one. Bonus points > for documenting new functions in the respective manual(s). Thanks for the suggestion. Updated the patch with the NEWS entry and manual doc. --8<-----------------------------cut here---------------start------------->8--- commit a80eda38ac4abefbbfd05719cb8ecd4ad9a85d68 Author: tino calancha Date: Tue Jan 23 08:52:48 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..37b8172502 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi @@ -1733,6 +1733,13 @@ Association Lists @end example @end defun +@defun assoc-delete-all key alist &optional test +This function is like @code{assq-delete-all} except that accepts +an optional argument @var{test} to compare the keys in @var{alist}. +@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---