From: Drew Adams <drew.adams@oracle.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>,
Nicolas Petton <nicolas@petton.fr>
Cc: Tom Tromey <tom@tromey.com>, emacs-devel@gnu.org
Subject: RE: map-put! and (setf (map-elt ...) ..) on lists
Date: Tue, 18 Dec 2018 07:42:12 -0800 (PST) [thread overview]
Message-ID: <6cd20f0b-2131-47b4-b37a-6d94a67558bb@default> (raw)
In-Reply-To: <jwvftuvhrja.fsf-monnier+emacs@gnu.org>
> >> map-put!:
> >> Associate KEY with VALUE in MAP and return VALUE.
> >> If KEY is already present in MAP, replace the associated value
> >> with VALUE.
>
> Not sure which version you were looking at,
The version I downloaded from Master on 2019-12-17,
the same day I wrote that.
(cl-defgeneric map-put! (map key value)
"Associate KEY with VALUE in MAP and return VALUE.
If KEY is already present in MAP, replace the associated value
with VALUE."
(map--dispatch map
:list (let ((p (assoc key map)))
(if p (setcdr p value)
(error "No place to change the mapping for %S" key)))
:hash-table (puthash key value map)
:array (aset map key value)))
> but what I see is:
> "Associate KEY with VALUE in MAP.
> If KEY is already present in MAP, replace the associated value
> with VALUE.
> This operates by modifying MAP in place.
> If it cannot do that, it signals the `map-not-inplace' error.
> If you want to insert an element without modifying MAP, use `map-
> insert'."
LGTM. Thanks for making that change/addition.
> I think normal code should never call this function
> directly and should use `(setf (map-elt ...) ..)` instead anyway!
> So, even a longwinded name would be perfectly fine.
1. Maybe such a statement should be made somewhere for
users, if it's not made already - and with maybe some
description of what is meant by either "normal code"
or (more likely) the abnormal code where it might make
sense to use this.
2. +1 for a long-winded name, if Emacs wants to make
the name proclaim that the function is destructive.
Maybe something like `map-put-in-place' or
`in-place-map-put' or `map-put-set' or `map-put-modify'
(no, I don't have a great suggestion).
next prev parent reply other threads:[~2018-12-18 15:42 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-14 17:32 map-put! and (setf (map-elt ...) ..) on lists Stefan Monnier
2018-12-16 16:32 ` Tom Tromey
2018-12-16 17:37 ` Drew Adams
2018-12-16 18:20 ` Stefan Monnier
2018-12-16 23:06 ` Tom Tromey
2018-12-17 3:16 ` Stefan Monnier
2018-12-17 4:08 ` Stefan Monnier
2018-12-17 11:41 ` Nicolas Petton
2018-12-17 16:06 ` Eli Zaretskii
2018-12-17 16:07 ` Drew Adams
2018-12-18 10:11 ` Nicolas Petton
2018-12-18 13:56 ` Stefan Monnier
2018-12-18 15:42 ` Drew Adams [this message]
2018-12-18 15:34 ` Drew Adams
2018-12-18 15:47 ` Stefan Monnier
2018-12-18 16:34 ` Nicolas Petton
2018-12-18 17:41 ` Drew Adams
2018-12-18 20:44 ` Nicolas Petton
2018-12-16 18:21 ` Stefan Monnier
2018-12-17 11:38 ` Nicolas Petton
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=6cd20f0b-2131-47b4-b37a-6d94a67558bb@default \
--to=drew.adams@oracle.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=nicolas@petton.fr \
--cc=tom@tromey.com \
/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).