From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Nicolas Petton Newsgroups: gmane.emacs.bugs Subject: bug#25929: 25.2; map-delete doesn't delete permanently 1st alist elt Date: Thu, 02 Mar 2017 13:34:57 +0100 Message-ID: <87efyfluvi.fsf@petton.fr> References: <87k288p2oq.fsf@gmail.com> <87k288kkqr.fsf@petton.fr> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1488458216 5164 195.159.176.226 (2 Mar 2017 12:36:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 2 Mar 2017 12:36:56 +0000 (UTC) Cc: Stefan Monnier , tino.calancha@gmail.com To: Tino Calancha , 25929@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Mar 02 13:36:49 2017 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 1cjPyO-0000aq-Ng for geb-bug-gnu-emacs@m.gmane.org; Thu, 02 Mar 2017 13:36:44 +0100 Original-Received: from localhost ([::1]:51882 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjPyU-0007AG-Kn for geb-bug-gnu-emacs@m.gmane.org; Thu, 02 Mar 2017 07:36:50 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjPxm-0006ni-Fx for bug-gnu-emacs@gnu.org; Thu, 02 Mar 2017 07:36:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjPxi-0003qh-V3 for bug-gnu-emacs@gnu.org; Thu, 02 Mar 2017 07:36:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37245) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cjPxi-0003qW-RD for bug-gnu-emacs@gnu.org; Thu, 02 Mar 2017 07:36:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cjPxi-0002MN-F8 for bug-gnu-emacs@gnu.org; Thu, 02 Mar 2017 07:36:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Nicolas Petton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 02 Mar 2017 12:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25929 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 25929-submit@debbugs.gnu.org id=B25929.14884581068994 (code B ref 25929); Thu, 02 Mar 2017 12:36:02 +0000 Original-Received: (at 25929) by debbugs.gnu.org; 2 Mar 2017 12:35:06 +0000 Original-Received: from localhost ([127.0.0.1]:35441 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cjPwo-0002L0-C3 for submit@debbugs.gnu.org; Thu, 02 Mar 2017 07:35:06 -0500 Original-Received: from petton.fr ([89.234.186.68]:60517) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cjPwm-0002KR-PR for 25929@debbugs.gnu.org; Thu, 02 Mar 2017 07:35:05 -0500 In-Reply-To: <87k288kkqr.fsf@petton.fr> 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:130045 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Nicolas Petton writes: > The alist is indeed modified within the `map-delete' function, but in an > unexpected way: if the first key is deleted, the variable `map' is > `setq'ed, which has no effect outside of the function. > > One fix would be to make `map-delete' a macro: Here's a fixed version: (defmacro map-delete (map key) "Delete KEY from MAP and return MAP. No error is signaled if KEY is not a key of MAP. If MAP is an array, store nil at the index KEY. =20=20 MAP can be a list, hash-table or array." (macroexp-let2 nil key `(progn (map--dispatch ,map :list (setf (alist-get ,key ,map nil t) nil) :hash-table (remhash ,key ,map) :array (and (>=3D ,key 0) (<=3D ,key (seq-length ,map)) (aset ,map ,key nil))) ,map))) And the associated regression test: (ert-deftest test-map-delete-first-key-alist () (let ((alist '((a . 1) (b . 2) (c . 3)))) (map-delete alist 'a) (should (null (map-elt alist 'a))))) Cheers, Nico --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJYuBFxAAoJECM1h6R8IHkQtFcH/3WgA6BADyy3I2tVH95mUjgX 6Tdk9YmRyBjGcr++7gN0i1G5EmTMKcT/+tZgJWoeVAHg04k0QX93AMe1mxyKz5ar iVpSx1OMBE5wyVnQtUIq5YLuZ9C4s7Skgd94txDVTyG9NgZqyO4AxfRAXdcGNxDi vTkCFEb5lRAgHr8JP/DOUPBayfhgT7pMLayvvlPxxSmaM2UJiFiidqXT8lzitl3b SdGj+hK97pq8YwJj1mXGeoEvCpXXiZq3Eg2Ka9Z/TvocqAKuTtf7XAhA7KcAurUT Y7biDns/RDFP0frUPCNW3tFOrRh3rTQTAO25viS7ACKe/X3K83Rmco05hwa7cbw= =tZE4 -----END PGP SIGNATURE----- --=-=-=--