[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: map-put! and (setf (map-elt ...) ..) on lists
From: |
Drew Adams |
Subject: |
RE: map-put! and (setf (map-elt ...) ..) on lists |
Date: |
Tue, 18 Dec 2018 07:42:12 -0800 (PST) |
> >> 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).
- Re: map-put! and (setf (map-elt ...) ..) on lists, (continued)
- Re: map-put! and (setf (map-elt ...) ..) on lists, Nicolas Petton, 2018/12/17
- Re: map-put! and (setf (map-elt ...) ..) on lists, Eli Zaretskii, 2018/12/17
- RE: map-put! and (setf (map-elt ...) ..) on lists, Drew Adams, 2018/12/17
- RE: map-put! and (setf (map-elt ...) ..) on lists, Nicolas Petton, 2018/12/18
- RE: map-put! and (setf (map-elt ...) ..) on lists, Drew Adams, 2018/12/18
- Re: map-put! and (setf (map-elt ...) ..) on lists, Stefan Monnier, 2018/12/18
- RE: map-put! and (setf (map-elt ...) ..) on lists, Nicolas Petton, 2018/12/18
- RE: map-put! and (setf (map-elt ...) ..) on lists, Drew Adams, 2018/12/18
- RE: map-put! and (setf (map-elt ...) ..) on lists, Nicolas Petton, 2018/12/18
- Re: map-put! and (setf (map-elt ...) ..) on lists, Stefan Monnier, 2018/12/18
- RE: map-put! and (setf (map-elt ...) ..) on lists,
Drew Adams <=
- Re: map-put! and (setf (map-elt ...) ..) on lists, Stefan Monnier, 2018/12/16
Re: map-put! and (setf (map-elt ...) ..) on lists, Nicolas Petton, 2018/12/17