Subject: bug#66509: 29.1.50; let-alist should support numeric indexing

From: Spencer Baugh <[email-masked]>
Date: Thu, 28 Aug 2025 15:05:08 -0400

Stefan Kangas <[email-masked]> writes:

> Stefan Kangas <[email-masked]> 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.

>From 82b4cc3ccc1ff2f8e82ff910ffa16fcf48eeefb4 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <[email-masked]>
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