[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#62068: 29.0.60; map-elt and map-insert for nested structures
From: |
Augusto Stoffel |
Subject: |
bug#62068: 29.0.60; map-elt and map-insert for nested structures |
Date: |
Sat, 11 Mar 2023 08:51:33 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
On Sat, 11 Mar 2023 at 04:22, Michael Heerdegen wrote:
> Augusto Stoffel <arstoffel@gmail.com> writes:
>
>> How did I miss that? In any case the more interesting bit is the other
>> function, which should then be renamed to `map-nested-insert'.
>
> Is that something one will really need often (honest question, I'm
> really curious)?
I think it's very useful when you need it :-). Actually, I wouldn't use
map-elt in any code, because I always know what type I'm dealing with.
I would just turn to this library for special maneuvers that the basic
API doesn't offer.
> If yes, I wonder if we should make it work as a
> generalized variable.
Maybe, but that's a separate story. First and most importantly, in my
opinion, the library should work right on values (as opposed to places).
>> Now, `map-nested-elt' has an inconsistency regarding the DEFAULT
>> argument which needs to be fixed.
>>
>> (map-nested-elt '(a nil) '(a) 1)
>> 1
>> (map-nested-elt '((a . nil)) '(a) 1)
>> 1
>> etc.
>>
>> While in the other hand:
>> (map-elt '(a nil) 'a 1)
>> nil
>> (map-elt '((a . nil)) 'a 1)
>> nil
>> etc.
>> [...]
>
> That's a good point indeed. However, `map-nested-elt' exists since the
> beginning of the library in 2015, so it could be that existing code
> relies on the behavior (maybe that's why you wanted to add a new
> function?).
(No, the reason was just pure oversight. Maybe "elt" is a weird word?
Why isn't it `map-get' and `map-nested-get'?)
> But it's a terrible inconsistency.
There are more consistency issues in this library, see bug#62067 and
bug#62117. Emacs has its quirks and one of the selling points of map.el
is to be a more consistent layer on top of the basic APIs, so I'd say
this need to be fixed.