diff options
| author | Lars Ingebrigtsen | 2019-10-13 01:29:32 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-10-13 01:29:32 +0200 |
| commit | 297f333a13b1f126e3f9c378ab856b970ee80283 (patch) | |
| tree | 731d7a02aa124fd7ad2d673e7105dd06d2b726cd /doc | |
| parent | b37fa09337b1f095e8d393d22d3d51ba2567c15c (diff) | |
| download | emacs-297f333a13b1f126e3f9c378ab856b970ee80283.tar.gz emacs-297f333a13b1f126e3f9c378ab856b970ee80283.zip | |
Document let-alist
* doc/lispref/lists.texi (Association Lists): Document let-alist
(bug#34842).
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/lists.texi | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index 746b4643c18..c06e95640d3 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi | |||
| @@ -1781,6 +1781,41 @@ compares the @sc{cdr} of each @var{alist} association instead of the | |||
| 1781 | @sc{car}. | 1781 | @sc{car}. |
| 1782 | @end defun | 1782 | @end defun |
| 1783 | 1783 | ||
| 1784 | @defmac let-alist alist body | ||
| 1785 | Creates a binding for each symbol used as keys the association list | ||
| 1786 | @var{alist}, prefixed with dot. This can be useful when accessing | ||
| 1787 | several items in the same association list, and it's best understood | ||
| 1788 | through a simple example: | ||
| 1789 | |||
| 1790 | @lisp | ||
| 1791 | (setq colors '((rose . red) (lily . white) (buttercup . yellow))) | ||
| 1792 | (let-alist colors | ||
| 1793 | (if (eq .rose 'red) | ||
| 1794 | .lily)) | ||
| 1795 | => white | ||
| 1796 | @end lisp | ||
| 1797 | |||
| 1798 | The @var{body} is inspected at compilation time, and only the symbols | ||
| 1799 | that appear in @var{body} with a @samp{.} as the first character in | ||
| 1800 | the symbol name will be bound. Finding the keys is done with | ||
| 1801 | @code{assq}, and the @code{cdr} of the return value of this | ||
| 1802 | @code{assq} is assigned as the value for the binding. | ||
| 1803 | |||
| 1804 | Nested association lists is supported: | ||
| 1805 | |||
| 1806 | @lisp | ||
| 1807 | (setq colors '((rose . red) (lily (belladonna . yellow) (brindisi . pink)))) | ||
| 1808 | (let-alist colors | ||
| 1809 | (if (eq .rose 'red) | ||
| 1810 | .lily.belladonna)) | ||
| 1811 | => yellow | ||
| 1812 | @end lisp | ||
| 1813 | |||
| 1814 | Nesting @code{let-alist} inside each other is allowed, but the code in | ||
| 1815 | the inner @code{let-alist} can't access the variables bound by the | ||
| 1816 | outer @code{let-alist}. | ||
| 1817 | @end defmac | ||
| 1818 | |||
| 1784 | @node Property Lists | 1819 | @node Property Lists |
| 1785 | @section Property Lists | 1820 | @section Property Lists |
| 1786 | @cindex property list | 1821 | @cindex property list |