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#25929: 25.2; map-delete doesn't delete permanently 1st alist elt Date: Thu, 2 Mar 2017 22:34:29 +0900 (JST) Message-ID: References: <87k288p2oq.fsf@gmail.com> <87k288kkqr.fsf@petton.fr> <87efyfluvi.fsf@petton.fr> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1488461717 18681 195.159.176.226 (2 Mar 2017 13:35:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 2 Mar 2017 13:35:17 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Cc: 25929@debbugs.gnu.org, Stefan Monnier , Tino Calancha To: Nicolas Petton Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Mar 02 14:35:10 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 1cjQsw-00040M-0u for geb-bug-gnu-emacs@m.gmane.org; Thu, 02 Mar 2017 14:35:10 +0100 Original-Received: from localhost ([::1]:52414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjQt1-0007nd-VE for geb-bug-gnu-emacs@m.gmane.org; Thu, 02 Mar 2017 08:35:16 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjQst-0007jQ-2F for bug-gnu-emacs@gnu.org; Thu, 02 Mar 2017 08:35:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjQsp-0003v4-4E for bug-gnu-emacs@gnu.org; Thu, 02 Mar 2017 08:35:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37285) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cjQsp-0003uz-1Y for bug-gnu-emacs@gnu.org; Thu, 02 Mar 2017 08:35:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cjQso-0003jx-Rg for bug-gnu-emacs@gnu.org; Thu, 02 Mar 2017 08:35: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: Thu, 02 Mar 2017 13:35: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.148846168214339 (code B ref 25929); Thu, 02 Mar 2017 13:35:02 +0000 Original-Received: (at 25929) by debbugs.gnu.org; 2 Mar 2017 13:34:42 +0000 Original-Received: from localhost ([127.0.0.1]:35483 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cjQsU-0003jD-7n for submit@debbugs.gnu.org; Thu, 02 Mar 2017 08:34:42 -0500 Original-Received: from mail-pg0-f67.google.com ([74.125.83.67]:35029) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cjQsS-0003j0-GI for 25929@debbugs.gnu.org; Thu, 02 Mar 2017 08:34:40 -0500 Original-Received: by mail-pg0-f67.google.com with SMTP id 1so9375120pgz.2 for <25929@debbugs.gnu.org>; Thu, 02 Mar 2017 05:34:40 -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=32HsnIYvQo36j+Cri1J4rdEu7TKUWwxpoG9n62Ea6hs=; b=A5CQBLOa2bcrtxDiWUc5GhuD2ab+bULO51BlLBx3r1xZjvZTCmGNZa18CktzDMh5gt bHlVwI5ZRPMzyYUNltmyWQxq41LzQ1hEbmkDj6OisUzgZ66thFSaAZlxlo8h3t2eHb3D hNylsTglb/tvlGuv0jQ8kgogSd5Rpf8XA7d+P0O9BP2RAXUirMKOu57zYpTQNOeCAp38 +3SNcmjyRGl2B+bFLYfe5pVyuyl4o72NBNIW843IxBLtE94jaeOm6t6HtEjPEXTPGMk5 GYi0Lcx18nikf8K2PK00Z3uUs4Lz9tdr3eiv+PjYGpfEHZCPCcRrAHt8iEJ2+KadUJVj vwOA== 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=32HsnIYvQo36j+Cri1J4rdEu7TKUWwxpoG9n62Ea6hs=; b=FR78Cv8NH9gkJzmBG/606ffHf7Gfgui4chIf/UYBL1BOQfyB0mL9EaRfkFYM/PI18P Pk8cHtTLg143YvBIRop5RXOFVuhE5ThMXlSK7MLQCpuv714Xa4HJ3Yh0A8w8Xr3WTuCL 6p8sGRoy6+S2kBLW11DLmOGWpi1JDaIaUWJ4MLd0QZfQ1x/JH6QvEBsq6MiPrgl8Ajxy tGQ+m6sXtcbLVqFEt6er8XO1PYthycGqKB+YuTissc8XK7XDAqS63ThVZf5DP56ub0g2 lpzUhBie4w3S7zKwDFbmEhCzKPUSrRzVSvtKIYQCaVBJRCJX2ZQWoRV9px3Yh+EatuBZ xcxw== X-Gm-Message-State: AMke39mwuZSlSMP5TU+f80rOLZX4qxcI7k5cLHl/5sdqnq34JXCI0BuqsSksrLF4/MKDMw== X-Received: by 10.99.66.197 with SMTP id p188mr2449695pga.107.1488461674648; Thu, 02 Mar 2017 05:34:34 -0800 (PST) Original-Received: from calancha-pc (104.81.147.124.dy.bbexcite.jp. [124.147.81.104]) by smtp.gmail.com with ESMTPSA id p4sm17385316pgd.50.2017.03.02.05.34.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Mar 2017 05:34:33 -0800 (PST) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc In-Reply-To: <87efyfluvi.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:130049 Archived-At: On Thu, 2 Mar 2017, Nicolas Petton wrote: > 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. > > 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 (>= ,key 0) > (<= ,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))))) Sorry, i don't understand why following doesn't work after the patch: ;; I have byte-compiled map.el after applying the patch. emacs -Q (let ((alist '((a . 1) (b . 2) (c . 3)))) (map-delete alist 'a) (map-elt alist 'a)) Debugger entered--Lisp error: (void-function map--dispatch) We shouldn't ask the user to compile the file on each interactive session in order to `map--dispatch' be defined. We might also mention in the doc strings that MAP must be a generalized variable or something. To explain that I) below is allowed but II) is not: I) (assq-delete-all 'foo '((foo . 1) (bar . 2))) II) (map-delete '((foo . 1) (bar . 2)) 'foo) Regards, Tino