diff options
| author | Spencer Baugh | 2025-08-28 15:04:39 -0400 |
|---|---|---|
| committer | Eli Zaretskii | 2025-08-30 13:59:18 +0300 |
| commit | b610f36d44dda3beb5cf2b8b65bfb0d005afed5c (patch) | |
| tree | c4246d570f0c3e7210801d677a42b4008d27d415 | |
| parent | 7efaa4657a10a0ec911a8fc8228260f30f1d7b55 (diff) | |
| download | emacs-b610f36d44dda3beb5cf2b8b65bfb0d005afed5c.tar.gz emacs-b610f36d44dda3beb5cf2b8b65bfb0d005afed5c.zip | |
Document and test 'let-alist' support for indexing
* etc/NEWS: Announce 'let-alist' support for indexing.
* test/lisp/emacs-lisp/let-alist-tests.el (let-alist-numbers):
Add a test for 'let-alist's support for indexing.
* doc/lispref/lists.texi (Association Lists): Document indexing
with 'let-alist'. (Bug#66509)
| -rw-r--r-- | doc/lispref/lists.texi | 13 | ||||
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/let-alist-tests.el | 11 |
3 files changed, 30 insertions, 0 deletions
diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index 37a07421e94..81edcc63d5b 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi | |||
| @@ -1934,6 +1934,19 @@ Nested association lists is supported: | |||
| 1934 | Nesting @code{let-alist} inside each other is allowed, but the code in | 1934 | Nesting @code{let-alist} inside each other is allowed, but the code in |
| 1935 | the inner @code{let-alist} can't access the variables bound by the | 1935 | the inner @code{let-alist} can't access the variables bound by the |
| 1936 | outer @code{let-alist}. | 1936 | outer @code{let-alist}. |
| 1937 | |||
| 1938 | Indexing into lists is also supported: | ||
| 1939 | |||
| 1940 | @lisp | ||
| 1941 | (setq colors '((rose . red) (lily . (yellow pink)))) | ||
| 1942 | (let-alist colors .lily.1) | ||
| 1943 | @result{} pink | ||
| 1944 | @end lisp | ||
| 1945 | |||
| 1946 | Note that forms like @samp{.0} or @samp{.3} are interpreted as numbers | ||
| 1947 | rather than as symbols, so they won't be bound to the corresponding | ||
| 1948 | values in ALIST. | ||
| 1949 | |||
| 1937 | @end defmac | 1950 | @end defmac |
| 1938 | 1951 | ||
| 1939 | @node Property Lists | 1952 | @node Property Lists |
| @@ -2854,6 +2854,12 @@ function 'load-path-filter-cache-directory-files', calling 'load' will | |||
| 2854 | cache the directories it scans and their files, and the following | 2854 | cache the directories it scans and their files, and the following |
| 2855 | lookups should be faster. | 2855 | lookups should be faster. |
| 2856 | 2856 | ||
| 2857 | +++ | ||
| 2858 | ** 'let-alist' supports indexing into lists. | ||
| 2859 | The macro 'let-alist' now interprets symbols containing numbers as list | ||
| 2860 | indices. For example, '.key.0' looks up 'key' in the alist and then | ||
| 2861 | returns its first element. | ||
| 2862 | |||
| 2857 | ** Lexical binding | 2863 | ** Lexical binding |
| 2858 | 2864 | ||
| 2859 | --- | 2865 | --- |
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 @@ See Bug#24641." | |||
| 100 | `[,(+ .a) ,(+ .a .b .b)]) | 100 | `[,(+ .a) ,(+ .a .b .b)]) |
| 101 | [1 5]))) | 101 | [1 5]))) |
| 102 | 102 | ||
| 103 | (ert-deftest let-alist-numbers () | ||
| 104 | "Check that .num indexes into lists." | ||
| 105 | (should (equal | ||
| 106 | (let-alist | ||
| 107 | '(((a . val1) (b . (nil val2))) | ||
| 108 | (c . (val3))) | ||
| 109 | (list .0 .0.a .0.b.1 .c.0)) | ||
| 110 | ;; .0 is interpreted as a number, so we can't use `let-alist' | ||
| 111 | ;; to do indexing alone. Everything else works though. | ||
| 112 | '(0.0 val1 val2 val3)))) | ||
| 113 | |||
| 103 | ;;; let-alist-tests.el ends here | 114 | ;;; let-alist-tests.el ends here |