unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: 34708@debbugs.gnu.org
Subject: bug#34708: alist-get has unclear documentation
Date: Fri, 15 Mar 2019 11:48:31 -0700	[thread overview]
Message-ID: <87wol09dog.fsf@ericabrahamsen.net> (raw)
In-Reply-To: <87a7hwqgj8.fsf@web.de> (Michael Heerdegen's message of "Fri, 15 Mar 2019 16:54:51 +0100")

Michael Heerdegen <michael_heerdegen@web.de> writes:

> 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)

I like it! Thanks for your work on this.





  reply	other threads:[~2019-03-15 18:48 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-02  4:50 bug#34708: alist-get has unclear documentation Miguel V. S. Frasson
2019-03-02  9:25 ` Michael Heerdegen
2019-03-02 15:40   ` Miguel V. S. Frasson
2019-03-02 18:10     ` Michael Heerdegen
2019-03-02 19:06       ` Eric Abrahamsen
2019-03-03  0:15         ` Phil Sainty
2019-03-03 12:50           ` Michael Heerdegen
2019-03-19  1:35             ` Michael Heerdegen
2019-03-02 19:51       ` Miguel V. S. Frasson
2019-03-02 20:32         ` Eric Abrahamsen
2019-03-03 11:32       ` Miguel V. S. Frasson
2019-03-03 12:21         ` Michael Heerdegen
2019-03-03 15:51           ` Drew Adams
2019-03-03 16:49             ` Eric Abrahamsen
2019-03-04 16:24             ` Eric Abrahamsen
2019-03-04 16:38               ` Michael Heerdegen
2019-03-04 17:16                 ` Eric Abrahamsen
2019-03-04 18:22                   ` Michael Heerdegen
2019-03-04 22:49                     ` Eric Abrahamsen
2019-03-05 12:35                       ` Michael Heerdegen
2019-03-05 22:50                         ` Eric Abrahamsen
2019-03-06  0:16                           ` Drew Adams
2019-03-11 13:39                             ` Michael Heerdegen
2019-03-11 14:52                               ` Drew Adams
2019-03-11 16:19                                 ` Michael Heerdegen
2019-03-11 17:48                                   ` Drew Adams
2019-03-12 13:04                                     ` Michael Heerdegen
2019-03-12 14:48                                       ` Drew Adams
2019-03-12 16:08                                         ` Michael Heerdegen
2019-03-12 16:48                                           ` Drew Adams
2019-03-12 17:45                                             ` Michael Heerdegen
2019-03-12 13:12                                 ` Michael Heerdegen
2019-03-12 14:53                                   ` Drew Adams
2019-03-12 15:38                                     ` Michael Heerdegen
2019-03-12 16:18                                       ` Drew Adams
2019-03-12 17:55                                         ` Michael Heerdegen
2019-03-15 15:54                                           ` Michael Heerdegen
2019-03-15 18:48                                             ` Eric Abrahamsen [this message]
2019-03-27 22:31                                               ` Michael Heerdegen
2019-04-19  1:33                                                 ` Michael Heerdegen
2019-04-19  2:24 ` bug#34708: Thanks Miguel V. S. Frasson
2019-04-19  4:18   ` Michael Heerdegen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wol09dog.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=34708@debbugs.gnu.org \
    --cc=michael_heerdegen@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).