GNU bug report logs - #47368
28.0.50; map-elt returns nil without "deprecated" TESTFN

Previous Next

Package: emacs;

Reported by: dalanicolai <dalanicolai <at> gmail.com>

Date: Wed, 24 Mar 2021 22:54:02 UTC

Severity: normal

Tags: patch

Found in versions 28.0.50, 27.1

Fixed in version 28.1

Done: "Basil L. Contovounesios" <contovob <at> tcd.ie>

Bug is archived. No further changes may be made.

Full log


Message #64 received at 47368 <at> debbugs.gnu.org (full text, mbox):

From: Adam Porter <adam <at> alphapapa.net>
To: 47368 <at> debbugs.gnu.org
Subject: Re: bug#47368: 28.0.50;
 map-elt returns nil without "deprecated" TESTFN
Date: Wed, 21 Jul 2021 10:34:14 -0500
Hi,

If I may chime in here, I'd like for map-elt to be usable with alists
having string keys.  It may not generally be very common in Elisp to
use alists with string keys, but in certain contexts, like preparing
JSON maps for encoding, it is.

In one of my packages, I came up with this workaround, which may be
tolerable when only used once in the whole package, but wouldn't be
nice to use more often:

    (cl-letf (((symbol-function 'alist-get)
               (lambda (key alist &optional _default _remove _testfn)
                 (cdr (assoc-string key alist)))))
      (let ((alist (list (cons "foo" "FOO")
                         (cons "bar" "BAR"))))
        (map-elt alist "foo")))  ;;=> "FOO"

In one of my other packages, I would have to use it more often, so I
guess I'll use alist-get for now.

In general, I think that using `equal' is a good solution.  It seems
like map-elt is intended to abstract over some Lisp implementation
details (to some extent, anyway), so using `equal' instead of `eq'
seems sensible, since I think it will usually DWIM.  If I really need
to compare Lisp object identity rather than equality, I'll probably
know how, and I probably won't need to do that as often, anyway.

Could this change be made for Emacs 28 and tagged for a 3.1 release of map.el?

Thanks,
Adam




This bug report was last modified 3 years and 329 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.