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 11:59:08 +0100 Message-ID: <87k288kkqr.fsf@petton.fr> References: <87k288p2oq.fsf@gmail.com> 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 1488452430 24762 195.159.176.226 (2 Mar 2017 11:00:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 2 Mar 2017 11:00:30 +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 12:00:19 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 1cjOSz-00050j-Ei for geb-bug-gnu-emacs@m.gmane.org; Thu, 02 Mar 2017 12:00:13 +0100 Original-Received: from localhost ([::1]:51542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjOT5-0000By-Jj for geb-bug-gnu-emacs@m.gmane.org; Thu, 02 Mar 2017 06:00:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjOSu-00007A-0u for bug-gnu-emacs@gnu.org; Thu, 02 Mar 2017 06:00:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjOSq-0008UC-6X for bug-gnu-emacs@gnu.org; Thu, 02 Mar 2017 06:00:08 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37171) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cjOSq-0008Ty-3L for bug-gnu-emacs@gnu.org; Thu, 02 Mar 2017 06:00:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cjOSp-0006it-0K for bug-gnu-emacs@gnu.org; Thu, 02 Mar 2017 06:00:03 -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 11:00: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.148845235925767 (code B ref 25929); Thu, 02 Mar 2017 11:00:02 +0000 Original-Received: (at 25929) by debbugs.gnu.org; 2 Mar 2017 10:59:19 +0000 Original-Received: from localhost ([127.0.0.1]:35370 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cjOS7-0006hX-Lx for submit@debbugs.gnu.org; Thu, 02 Mar 2017 05:59:19 -0500 Original-Received: from petton.fr ([89.234.186.68]:59306) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cjOS5-0006hK-Nf for 25929@debbugs.gnu.org; Thu, 02 Mar 2017 05:59:18 -0500 In-Reply-To: <87k288p2oq.fsf@gmail.com> 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:130036 Archived-At: --=-=-= Content-Type: text/plain Tino Calancha writes: > (cl-loop for i below 3 collect > (let ((map (list (cons 0 3) > (cons 1 4) > (cons 2 5)))) > (map-delete map i) > (null (map-elt map i)))) > => (nil t t) ; The first pair, i.e. '(0 . 3) is not permanently deleted. > > I've used the word 'permantly' because it seems it is temporary > deleted: > > (cl-loop for i below 3 collect > (let ((map (list (cons 0 3) > (cons 1 4) > (cons 2 5)))) > (null (map-elt > (map-delete map i) > i)))) > => (t t t) 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: (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. MAP can be a list, hash-table or array." `(macroexp-let2 nil key (map--dispatch ,map :list (setf (alist-get ,key ,map nil t) nil) :hash-table (remhash ,key ,map) :array (and (>= ,key 0) (<= ,key (seq-length ,map)) (aset ,map ,key nil))) ,map)) WDYT? Cheers, Nico --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJYt/r8AAoJECM1h6R8IHkQy60H/3G9VbU2OXHESWYyc549wmT3 HQa7PF2uavzTodgzw0z3lEwdTU+wSu+hproCDqdnXKbz07mnT06D6Jruy3nmb4Vq WqbQ6Flx2E9tYzd9wt+WIGD4a7VllyFqc/sNYmtJKlQxeMWFxe7zsKekiJLZ/j6D 5WMt8Yc0TBTOGKRyLns8mGFOaJ+DwDwotHYtpXgVlT8+kvq+AwVYTr62Fgdde+MN LHGsFRWNzCVcRy7UUf56YHpw+AWmnJAFul/DhYWMr32disxqR3wtlAsn4yD2YqkO rrxjK3GZ6fw7/NgUxyFI6ARvvV2+DfRgvxSOdxbXywJ5aB2xn5S8bpEbw8MTItQ= =uP/E -----END PGP SIGNATURE----- --=-=-=--