From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#34842: 26.1; Alist documentation: let-alist Date: Sun, 13 Oct 2019 03:03:07 +0100 Message-ID: <871rvh9zc4.fsf@tcd.ie> References: <87eezhh763.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="119538"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 34842@debbugs.gnu.org, =?UTF-8?Q?Sebasti=C3=A1n_?= =?UTF-8?Q?Mon=C3=ADa?= To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 13 04:04:20 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iJTF3-000UuG-AD for geb-bug-gnu-emacs@m.gmane.org; Sun, 13 Oct 2019 04:04:17 +0200 Original-Received: from localhost ([::1]:37166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJTF1-0004HQ-MD for geb-bug-gnu-emacs@m.gmane.org; Sat, 12 Oct 2019 22:04:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56852) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJTEr-0004H0-E4 for bug-gnu-emacs@gnu.org; Sat, 12 Oct 2019 22:04:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJTEp-0006r6-4M for bug-gnu-emacs@gnu.org; Sat, 12 Oct 2019 22:04:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54049) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iJTEo-0006r0-IB for bug-gnu-emacs@gnu.org; Sat, 12 Oct 2019 22:04:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iJTEo-00012t-BX for bug-gnu-emacs@gnu.org; Sat, 12 Oct 2019 22:04:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 13 Oct 2019 02:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34842 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed Original-Received: via spool by 34842-submit@debbugs.gnu.org id=B34842.15709322013972 (code B ref 34842); Sun, 13 Oct 2019 02:04:02 +0000 Original-Received: (at 34842) by debbugs.gnu.org; 13 Oct 2019 02:03:21 +0000 Original-Received: from localhost ([127.0.0.1]:34637 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iJTE6-00011x-K4 for submit@debbugs.gnu.org; Sat, 12 Oct 2019 22:03:19 -0400 Original-Received: from mail-wr1-f53.google.com ([209.85.221.53]:33851) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iJTE3-00011h-N5 for 34842@debbugs.gnu.org; Sat, 12 Oct 2019 22:03:16 -0400 Original-Received: by mail-wr1-f53.google.com with SMTP id j11so15740107wrp.1 for <34842@debbugs.gnu.org>; Sat, 12 Oct 2019 19:03:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=+ebZRqyHvPncejgCp6ZVQH6d5TTBjqOZw/jyS+Q5rKM=; b=VnGUJgDb65Lujtq3uaeBqJLKysYDsfRm3+MyWpVPZNbmCGpOjCSMRS+Y6FJtjvsXsS 9CWtqaWXcKGxFN9/yzblA9earEs3bsCJ9jloZHoR3oPjRv1kwqccT96CRs/wd08J5YfY 07VfiHW2XDQiHpwd1kLAZ5w12mDIgUQI4Cb/DmLR/Y9u+LMDdFQkha0A+0/A5pCpMFOW eKVfQVALLZQmWxmDQ2bRf5ib5ZDWuI1IQcxdu5ZcFmkVsIH36C5uadAbVIZA2jYtv1Pq VWEkhj0kt4jbRuZwsNBxPu8SVokfaQSxPNUbEivli9ChrdVlgGCJSLZ9ZOOc4FFgS1jk kz3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=+ebZRqyHvPncejgCp6ZVQH6d5TTBjqOZw/jyS+Q5rKM=; b=lpMD2p5oMpXabafuQzYxmb6iNlZM5aqO55QWEX8Y3fn+4jQ6CPwxnFNJKoo0/yaZ8G MOykvtLS7V3eiRH0kP7fbood02MvogHEKsG7Fqy6NS51HJ8QRC9nq9SyCBshg5zE32w5 tBi+GnJI59WEfda2ge1D30YsnCa8HUgPy9bBO9PmK3XXRK8YcZqSxy5ZIy/x7aZK6ILP v9IfVlJSBQsE+0FTfy16kAqwc9MUd1wRe3dWAzw+DrMcb9/jHVmnKHFkXbMa6MQ7jrX+ avN1OqFOQ1M056KZYPOqKYHIi3irYT8Qa03JziM6zCaIRCWggRJKv506vfaxJklmQn4p NADQ== X-Gm-Message-State: APjAAAXs5vxWWGtRZ2AQCI7o/x7+jLOP3DfgExX6h3D1VSfIykXxWEXV nLN1y4YENT/gGmMnJlUfJX2iFw== X-Google-Smtp-Source: APXvYqyxsmFhr7olZppq8+r11MsKscJB8O6aI75fHIV6L9+z72NOv9LkXydb841dmuHUZOOXtMCQvg== X-Received: by 2002:adf:dd8b:: with SMTP id x11mr19453958wrl.113.1570932189855; Sat, 12 Oct 2019 19:03:09 -0700 (PDT) Original-Received: from localhost ([2a02:8084:20e2:c380:92bd:1bfd:38fc:fae2]) by smtp.gmail.com with ESMTPSA id r18sm21689968wme.48.2019.10.12.19.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Oct 2019 19:03:08 -0700 (PDT) In-Reply-To: <87eezhh763.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sun, 13 Oct 2019 01:32:04 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:169087 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Lars Ingebrigtsen writes: > Sebasti=C3=A1n Mon=C3=ADa writes: > >> The macro let-alist is too useful to work with JSON-parsed data for it t= o be >> missing from the docs. >> >> In the page >> https://www.gnu.org/software/emacs/manual/html_node/elisp/Association-Li= sts.html >> we should add some documentation about it. Below a suggestion. >> >> Thank you! >> >> =E2=80=94 Macro: let-alist `value` >> Creates a binding for each symbol in the association list `value`, prefi= xed with >> dot. This is very useful when accessing several items in the same alist,= and it's >> best understood through a simple example: >> >> (setq colors '((rose red) (lily white) (buttercup yellow))) >> (let-alist colors >> (print .rose) >> (print .buttercup)) >> =E2=87=92 red >> =E2=87=92 yellow > > Even though I question the usefulness of this macro (especially since it > doesn't nest well, so it seems just kinda ad-hoc), I've now documented > it along the lines you suggest. Drew wanted the manual to describe more > fully the actual details behind the implementation, but I think that > doesn't add much clarity. Thanks. The following constitute what I think are some opportunities for clarifying the current doc. WDYT? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=let-alist.diff diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index c06e95640d..00c2211c36 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi @@ -1781,39 +1781,51 @@ Association Lists @sc{car}. @end defun -@defmac let-alist alist body -Creates a binding for each symbol used as keys the association list -@var{alist}, prefixed with dot. This can be useful when accessing -several items in the same association list, and it's best understood -through a simple example: +@defmac let-alist alist body@dots{} +This macro sets up a local binding for each variable that is used in +@var{body} and whose name starts with a dot, and then evaluates +@var{body}. In each case the dot-prefixed variable is bound to the +value associated with its dot-less suffix in the association list +@var{alist}. + +This can be convenient when accessing several items in the same +association list, and is best understood through a simple example: @lisp (setq colors '((rose . red) (lily . white) (buttercup . yellow))) (let-alist colors (if (eq .rose 'red) .lily)) -=> white + @result{} white @end lisp -The @var{body} is inspected at compilation time, and only the symbols -that appear in @var{body} with a @samp{.} as the first character in -the symbol name will be bound. Finding the keys is done with -@code{assq}, and the @code{cdr} of the return value of this -@code{assq} is assigned as the value for the binding. +The @var{body} is inspected at compilation time, and only those +variables that appear in @var{body} and whose name starts with a +@samp{.} are bound. Each such @var{.symbol} is bound to the @sc{cdr} +of the first association for @var{symbol} in @var{alist} using +@code{assq}. If no such association exists, @var{.symbol} is bound to +@code{nil}: -Nested association lists is supported: +@lisp +(let-alist colors + .tulip) + @result{} nil +@end lisp + +Nested association lists are also supported by concatenating multiple +dot-prefixed symbols: @lisp (setq colors '((rose . red) (lily (belladonna . yellow) (brindisi . pink)))) (let-alist colors (if (eq .rose 'red) .lily.belladonna)) -=> yellow + @result{} yellow @end lisp -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 -outer @code{let-alist}. +Nesting @code{let-alist} inside calls to itself is allowed, but the +@var{body} of the inner @code{let-alist} can't access the bindings set +up by the outer @code{let-alist}. @end defmac @node Property Lists --=-=-= Content-Type: text/plain -- Basil --=-=-=--