mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-07 06:50:23 -08:00
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)
This commit is contained in:
parent
7efaa4657a
commit
b610f36d44
3 changed files with 30 additions and 0 deletions
|
|
@ -1934,6 +1934,19 @@ Nested association lists is supported:
|
||||||
Nesting @code{let-alist} inside each other is allowed, but the code in
|
Nesting @code{let-alist} inside each other is allowed, but the code in
|
||||||
the inner @code{let-alist} can't access the variables bound by the
|
the inner @code{let-alist} can't access the variables bound by the
|
||||||
outer @code{let-alist}.
|
outer @code{let-alist}.
|
||||||
|
|
||||||
|
Indexing into lists is also supported:
|
||||||
|
|
||||||
|
@lisp
|
||||||
|
(setq colors '((rose . red) (lily . (yellow pink))))
|
||||||
|
(let-alist colors .lily.1)
|
||||||
|
@result{} pink
|
||||||
|
@end lisp
|
||||||
|
|
||||||
|
Note that forms like @samp{.0} or @samp{.3} are interpreted as numbers
|
||||||
|
rather than as symbols, so they won't be bound to the corresponding
|
||||||
|
values in ALIST.
|
||||||
|
|
||||||
@end defmac
|
@end defmac
|
||||||
|
|
||||||
@node Property Lists
|
@node Property Lists
|
||||||
|
|
|
||||||
6
etc/NEWS
6
etc/NEWS
|
|
@ -2854,6 +2854,12 @@ function 'load-path-filter-cache-directory-files', calling 'load' will
|
||||||
cache the directories it scans and their files, and the following
|
cache the directories it scans and their files, and the following
|
||||||
lookups should be faster.
|
lookups should be faster.
|
||||||
|
|
||||||
|
+++
|
||||||
|
** 'let-alist' supports indexing into lists.
|
||||||
|
The macro 'let-alist' now interprets symbols containing numbers as list
|
||||||
|
indices. For example, '.key.0' looks up 'key' in the alist and then
|
||||||
|
returns its first element.
|
||||||
|
|
||||||
** Lexical binding
|
** Lexical binding
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
|
||||||
|
|
@ -100,4 +100,15 @@ See Bug#24641."
|
||||||
`[,(+ .a) ,(+ .a .b .b)])
|
`[,(+ .a) ,(+ .a .b .b)])
|
||||||
[1 5])))
|
[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
|
;;; let-alist-tests.el ends here
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue