[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#34708: alist-get has unclear documentation
From: |
Michael Heerdegen |
Subject: |
bug#34708: alist-get has unclear documentation |
Date: |
Fri, 15 Mar 2019 16:54:51 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Michael Heerdegen <michael_heerdegen@web.de> writes:
> Actually, it's not even trivial at all. Setting alist-get as place
> could also build a new alist, leaving the one stored in the ALIST place
> intact, and set place ALIST to the new list. But it potentially
> modifies the list stored in place ALIST. That's not inevitable, so it
> could be worth telling that.
I tried that - see the draft at the end of the message. And I tried to
cover everything that has been noted here to some degree while still
keeping the docstring fluent and at an acceptable length.
I did not touch the manual, maybe someone else wants to give that a try?
From 3b8ef1ee9d9a5001e2de930ec34e3bdd3d4f87ad Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen@web.de>
Date: Tue, 12 Mar 2019 15:13:55 +0100
Subject: [PATCH] WIP: Improve documentation of alist-get
(Bug#34708)...
---
lisp/subr.el | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/lisp/subr.el b/lisp/subr.el
index 4024c68e68..8ea8fb602c 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -756,9 +756,31 @@ alist-get
If KEY is not found in ALIST, return DEFAULT.
Use TESTFN to lookup in the alist if non-nil. Otherwise, use `assq'.
-This is a generalized variable suitable for use with `setf'.
+You can use `alist-get' in PLACE expressions. This will modify
+an existing association (more precisely, the first one if
+multiple exist), or add a new element to the beginning of ALIST,
+destructively modifying the list stored in ALIST.
+
+Example:
+
+ (setq foo '((a . 0)))
+ (setf (alist-get 'a foo) 1
+ (alist-get 'b foo) 2)
+
+ foo ==> ((b . 2) (a . 1))
+
+
When using it to set a value, optional argument REMOVE non-nil
-means to remove KEY from ALIST if the new value is `eql' to DEFAULT."
+means to remove KEY from ALIST if the new value is `eql' to
+DEFAULT (more precisely the first found association will be
+deleted from the alist).
+
+Example:
+
+ (setq foo '((a . 1) (b . 2)))
+ (setf (alist-get 'b foo nil 'remove) nil)
+
+ foo ==> ((a . 1))"
(ignore remove) ;;Silence byte-compiler.
(let ((x (if (not testfn)
(assq key alist)
--
2.20.1
Michael.
- bug#34708: alist-get has unclear documentation, (continued)
- bug#34708: alist-get has unclear documentation, Michael Heerdegen, 2019/03/12
- bug#34708: alist-get has unclear documentation, Drew Adams, 2019/03/12
- bug#34708: alist-get has unclear documentation, Michael Heerdegen, 2019/03/12
- bug#34708: alist-get has unclear documentation, Drew Adams, 2019/03/12
- bug#34708: alist-get has unclear documentation, Michael Heerdegen, 2019/03/12
- bug#34708: alist-get has unclear documentation, Michael Heerdegen, 2019/03/12
- bug#34708: alist-get has unclear documentation, Drew Adams, 2019/03/12
- bug#34708: alist-get has unclear documentation, Michael Heerdegen, 2019/03/12
- bug#34708: alist-get has unclear documentation, Drew Adams, 2019/03/12
- bug#34708: alist-get has unclear documentation, Michael Heerdegen, 2019/03/12
- bug#34708: alist-get has unclear documentation,
Michael Heerdegen <=
- bug#34708: alist-get has unclear documentation, Eric Abrahamsen, 2019/03/15
- bug#34708: alist-get has unclear documentation, Michael Heerdegen, 2019/03/27