GNU bug report logs -
#62068
29.0.60; map-elt and map-insert for nested structures
Previous Next
Full log
View this message in rfc822 format
On Fri, 10 Mar 2023 at 02:18, Michael Heerdegen wrote:
> Augusto Stoffel <arstoffel <at> gmail.com> writes:
>
>> I would like to suggest the following two functions to deal with nested
>> maps. Let me know if you would like to see a patch.
>>
>> (defun map-elt-in (map keys &optional default)
>> "Look up a nested sequence of KEYS in MAP and return its associated value.
>> KEYS is any sequence type supported by `seq'. If a key is not
>> found in any intermediate step, return DEFAULT, which defaults to
>> nil."
>> (catch 'map--break
>> (seq-reduce (lambda (m k)
>> (let ((v (map-elt m k 'map--default)))
>> (if (eq v 'map--default)
>> (throw 'map--break default)
>> v)))
>> keys
>> map)))
>
> Isn't this more or less the same as `map-nested-elt'?
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'.
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.
Also inconsistent with the rest of Emacs:
(let ((m (make-hash-table)))
(puthash 'a nil m)
(gethash 'a m 1))
nil
(alist-get 'a '((a . nil)) 1)
nil
This bug report was last modified 2 years and 152 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.