GNU bug report logs - #66509
29.1.50; let-alist should support numeric indexing

Previous Next

Package: emacs;

Reported by: Spencer Baugh <sbaugh <at> janestreet.com>

Date: Thu, 12 Oct 2023 22:04:01 UTC

Severity: wishlist

Tags: patch

Found in version 29.1.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Full log


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

From: Spencer Baugh <sbaugh <at> janestreet.com>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 66509 <at> debbugs.gnu.org
Subject: Re: bug#66509: 29.1.50; let-alist should support numeric indexing
Date: Thu, 28 Aug 2025 15:05:08 -0400
[Message part 1 (text/plain, inline)]
Stefan Kangas <stefankangas <at> gmail.com> writes:

> Stefan Kangas <stefankangas <at> gmail.com> writes:
>
>> reopen 66509
>> thanks
>>
>>>> Pushed to master (commit ae4171efdc6).
>>>>
>>>> I'm therefore closing this bug report.
>>
>> I'm reopening this bug report, based on this request from Robert Pluim:
>>
>>> Would it be possible to update the elisp manual as well (and maybe add
>>> an entry to NEWS)?
>>
>> I think that should be done also, so I'm reopening the bug to track that
>> work.  Spencer, do you think you could you please address it?
>>
>> Bonus points for adding tests, as requested by Eli.
>
> Ping!

Done in attached patch.

[0001-Document-and-test-let-alist-support-for-indexing.patch (text/x-patch, inline)]
From 82b4cc3ccc1ff2f8e82ff910ffa16fcf48eeefb4 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh <at> janestreet.com>
Date: Thu, 28 Aug 2025 15:04:39 -0400
Subject: [PATCH] Document and test let-alist support for indexing

* etc/NEWS: Announce let-alist support for indexing. (bug#66509)
* test/lisp/emacs-lisp/let-alist-tests.el (let-alist-numbers):
Add a test for let-alist's support for indexing.
---
 etc/NEWS                                |  6 ++++++
 test/lisp/emacs-lisp/let-alist-tests.el | 11 +++++++++++
 2 files changed, 17 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 058f0e896eb..1a9fe46d269 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2791,6 +2791,12 @@ function 'load-path-filter-cache-directory-files', calling 'load' will
 cache the directories it scans and their files, and the following
 lookups should be faster.
 
++++
+** 'let-alist' supports indexing into lists
+The macro 'let-alist' now interprets symbols containing numbers as list
+indexes.  For example, '.key.0' looks up 'key' in the alist and then
+returns its first element.
+
 ** Lexical binding
 
 ---
diff --git a/test/lisp/emacs-lisp/let-alist-tests.el b/test/lisp/emacs-lisp/let-alist-tests.el
index 988b05b488c..b23178f5467 100644
--- a/test/lisp/emacs-lisp/let-alist-tests.el
+++ b/test/lisp/emacs-lisp/let-alist-tests.el
@@ -100,4 +100,15 @@ let-alist--vectors
                    `[,(+ .a) ,(+ .a .b .b)])
                  [1 5])))
 
+(ert-deftest let-alist-numbers ()
+  "Check that .num indexes into lists."
+  (should (equal
+           (let-alist
+               '(((a . val1) (b . (nil val2)))
+                 (c . (val3)))
+             (list .0 .0.a .0.b.1 .c.0))
+           ;; .0 is interpreted as a number, so we can't use `let-alist'
+           ;; to do indexing alone.  Everything else works though.
+           '(0.0 val1 val2 val3))))
+
 ;;; let-alist-tests.el ends here
-- 
2.43.7


This bug report was last modified 20 days ago.

Previous Next


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