unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: Nicolas Petton <nicolas@petton.fr>
Cc: 25929@debbugs.gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>,
	Tino Calancha <tino.calancha@gmail.com>
Subject: bug#25929: 25.2; map-delete doesn't delete permanently 1st alist elt
Date: Thu, 2 Mar 2017 22:34:29 +0900 (JST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1703022218480.30755@calancha-pc> (raw)
In-Reply-To: <87efyfluvi.fsf@petton.fr>



On Thu, 2 Mar 2017, Nicolas Petton wrote:

> Nicolas Petton <nicolas@petton.fr> 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





  reply	other threads:[~2017-03-02 13:34 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-02  7:17 bug#25929: 25.2; map-delete doesn't delete permanently 1st alist elt Tino Calancha
2017-03-02  8:56 ` Nicolas Petton
2017-03-02 10:59 ` Nicolas Petton
2017-03-02 11:30   ` Tino Calancha
2017-03-02 12:27     ` Nicolas Petton
2017-03-02 12:34   ` Nicolas Petton
2017-03-02 13:34     ` Tino Calancha [this message]
2017-03-02 15:12     ` Stefan Monnier
2017-03-04  0:04       ` Michael Heerdegen
2017-03-04  0:16         ` Michael Heerdegen
2017-03-21 20:41         ` Lars Ingebrigtsen
2017-03-22 11:55           ` Michael Heerdegen
2017-03-22 12:01             ` Lars Ingebrigtsen
2017-03-22 12:56               ` Noam Postavsky
2017-03-22 13:31                 ` Lars Ingebrigtsen
2017-03-22 14:43                   ` Michael Heerdegen
2017-03-22 17:04                   ` Stefan Monnier
2017-03-22 17:23                     ` Lars Ingebrigtsen
2017-03-22 20:31                       ` Stefan Monnier
2017-03-22 17:02               ` Stefan Monnier
2017-03-29 15:25             ` bug#25929: 25.2; plists and map-* Lars Ingebrigtsen
2017-03-29 15:36               ` Nicolas Petton
2017-03-21 11:35       ` bug#25929: 25.2; map-delete doesn't delete permanently 1st alist elt Nicolas Petton
2017-03-21 15:11         ` Stefan Monnier
2017-03-21 18:06           ` Nicolas Petton
2017-03-21 20:29             ` Stefan Monnier
2017-04-26  7:58               ` Nicolas Petton
2017-03-02 12:36   ` npostavs
2017-03-02 12:45     ` Nicolas Petton
2022-04-26 13:34 ` Lars Ingebrigtsen
2022-04-28  3:17   ` Richard Stallman
2022-04-28 16:00     ` Drew Adams

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.1703022218480.30755@calancha-pc \
    --to=tino.calancha@gmail.com \
    --cc=25929@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=nicolas@petton.fr \
    /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).