From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Artur Malabarba Newsgroups: gmane.emacs.bugs Subject: bug#66509: 29.1.50; let-alist should support numeric indexing Date: Mon, 16 Sep 2024 23:07:33 -0300 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000c0399b06224727f8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35447"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Spencer Baugh , 66509@debbugs.gnu.org To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Sep 17 04:10:07 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sqNfK-00091V-A6 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 17 Sep 2024 04:10:06 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sqNfA-00087L-Db; Mon, 16 Sep 2024 22:09:57 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqNf3-00086u-2v for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2024 22:09:50 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sqNf2-0006Mb-39 for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2024 22:09:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=Date:From:In-Reply-To:References:MIME-Version:To:Subject; bh=2qnJ/rmHpIBW0cFd4LmPJYOopVlldz8Z7z5j4rCdE+s=; b=u04Ju2kXru862YtYdfcRvy4We6MPwL8ST4lYE5ZYsyc0X61crPappUk3QOS6bAfwr/Wd7zmRnO+FMduopLXFUwBoa7kOlMXmvmvtJfkYP/waxdxuIUVYN4zkepW+Gzvz0n/is5Hndb/FG+ycTXYm0eekUQGasc2L9by905KPlgiOEwN88zGj91r9Gj3oMRTO9rsJRlsMS+HRDkjYc2AyM0J6h5ibo+RIFP+7CKjlU0hoQ0OxSQUAjq51oMfeMdzGLuy5Npa5tLK6qOCdHcuqy9ah1PprIeR/eMIDPnQlFuHOjBqxgEpNBrp6iCD91yeThXPWrihVl40rMYjQmFe6yQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sqNfF-0008Iq-S7 for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2024 22:10:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Artur Malabarba Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 17 Sep 2024 02:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66509 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 66509-submit@debbugs.gnu.org id=B66509.172653894831831 (code B ref 66509); Tue, 17 Sep 2024 02:10:01 +0000 Original-Received: (at 66509) by debbugs.gnu.org; 17 Sep 2024 02:09:08 +0000 Original-Received: from localhost ([127.0.0.1]:53695 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sqNeN-0008HL-Id for submit@debbugs.gnu.org; Mon, 16 Sep 2024 22:09:08 -0400 Original-Received: from mail-pg1-f170.google.com ([209.85.215.170]:52418) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sqNeL-0008Go-Ex for 66509@debbugs.gnu.org; Mon, 16 Sep 2024 22:09:06 -0400 Original-Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-7d4fbe62bf5so2283383a12.0 for <66509@debbugs.gnu.org>; Mon, 16 Sep 2024 19:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726538865; x=1727143665; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=2qnJ/rmHpIBW0cFd4LmPJYOopVlldz8Z7z5j4rCdE+s=; b=Ufnf8AmbbphIv3JYbZ2J0S4Y2dIvZ0VxLCf6xXYkE33Xqo694F1W4sHeSNAzqnNmMg x++kDzrH7lreum1Eq8CuIa3uPtV69jcA30EDXxrUblgfcK+/9fGVJG9GJxEdCwei47hJ XOw9XWd1xnyhIODHEZv6nY9yECI97rOZxfH57t78UPGpLcK/NVKR1nqOVQ4L/eyRLZe1 DLBGTDhpBvX7EdGdR3/PTi/TXaCQvNHGFRQ0SKVN5i1kCfZCmA+NsBD7XTd3NG7tF4Ss rcaenDwddTWHFqw5m/YQz/Buug6fwhx465P9KmDx1c5C99on8nRnz0DYQ9H7SpuYad0a Ex1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726538865; x=1727143665; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2qnJ/rmHpIBW0cFd4LmPJYOopVlldz8Z7z5j4rCdE+s=; b=HED/lt2DK67S/lo98QWJgIjsbByBu73EarP+UZTrd+OzcUIGhPaC2crqSwNCYa8s5D ZaGUsAvSusn2mAyJkkDDvEkl7ClJqkRgx9wr4pSedqVIn+IO6kro0ItL07u99avrmzK6 kDBCkVKAe2Nrdn0rHXfjSx2V8mKVQIzMNCobikeXE58vk7b66v48rEdJ/495xJ84OJzD 72nqwD2tO7gMoOEyx6VVJL/NsucxGjNem+RnXFF1AZlLZ4Wv5jDfzQsUVEP+GJRx7CZe 4CkLgjbQP6WftRU/dNpeXSeau5oMgE7/h3TOSOZ2DFpVMT0rWGXhUdjVa5oHrsZJX+do U9ow== X-Forwarded-Encrypted: i=1; AJvYcCXzrJKRka469Y/5VIOo76ptQIb+6uF+KWmyZEDASJNy3ZtmgK4QpNVdht7k4gw0hAmef9iIDQ==@debbugs.gnu.org X-Gm-Message-State: AOJu0YwAJoZfRSlgcUEkD6RMACrCteyxCLgTg9pi3AzCftWv2iG2ttOT ySWph5HYvrESI4xzrUS8dxCYgo3EpwBmLqTThn25CL6IajhlBPgayWXFCzpn5XgPmAXjLfRSq70 +XPd/vyctIxW5otysCjLnc80Mc2Q= X-Google-Smtp-Source: AGHT+IFq282y5bA8EA3WqXxruWI/pXxXknKjY/NPe3kJtYS5bo8UsUcRiR0g7Fo5Yj9lB3d8V+43n6reFayYt9x11U4= X-Received: by 2002:a05:6300:6681:b0:1cf:52fe:38ff with SMTP id adf61e73a8af0-1d112b360fbmr19650506637.8.1726538865192; Mon, 16 Sep 2024 19:07:45 -0700 (PDT) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:291923 Archived-At: --000000000000c0399b06224727f8 Content-Type: text/plain; charset="UTF-8" Hi all, The patch looks good. Stefan, would you mind applying it? (It'll take a while for me to get everything configured.) best, Artur On Tue, 10 Sept 2024 at 20:22, Stefan Kangas wrote: > Artur, do you have any thoughts on the below patch? > > Spencer Baugh writes: > > > From 28e52a343f72dddd991cafd23fea910cc5f64ac5 Mon Sep 17 00:00:00 2001 > > From: Spencer Baugh > > Date: Thu, 12 Oct 2023 18:01:46 -0400 > > Subject: [PATCH] Support numeric indexing in let-alist > > > > let-alist is very useful. But sometimes an alist contains a list in > > the middle, which contains yet more alists. Previously, this was > > somewhat painful to deal with, and required something like: > > > > (let-alist alist > > (let-alist (nth 0 .a) > > (let-alist (nth 3 .b) > > .c))) > > > > Now, the following works: > > > > (let-alist alist > > .a.0.b.3.c) > > > > * lisp/emacs-lisp/let-alist.el (let-alist--access-sexp): Properly > > parse numbers. > > (let-alist--list-to-sexp): Use nth to handle numbers. > > (let-alist): Update docs. > > --- > > lisp/emacs-lisp/let-alist.el | 25 +++++++++++++++---------- > > 1 file changed, 15 insertions(+), 10 deletions(-) > > > > diff --git a/lisp/emacs-lisp/let-alist.el b/lisp/emacs-lisp/let-alist.el > > index d9ad46b2af7..de7c087bf2a 100644 > > --- a/lisp/emacs-lisp/let-alist.el > > +++ b/lisp/emacs-lisp/let-alist.el > > @@ -36,22 +36,23 @@ > > ;; symbol inside body is let-bound to their cdrs in the alist. Dotted > > ;; symbol is any symbol starting with a `.'. Only those present in > > ;; the body are let-bound and this search is done at compile time. > > +;; A number will result in a list index. > > ;; > > ;; For instance, the following code > > ;; > > ;; (let-alist alist > > -;; (if (and .title .body) > > +;; (if (and .title.0 .body) > > ;; .body > > ;; .site > > ;; .site.contents)) > > ;; > > ;; essentially expands to > > ;; > > -;; (let ((.title (cdr (assq 'title alist))) > > +;; (let ((.title.0 (nth 0 (cdr (assq 'title alist)))) > > ;; (.body (cdr (assq 'body alist))) > > ;; (.site (cdr (assq 'site alist))) > > ;; (.site.contents (cdr (assq 'contents (cdr (assq 'site > alist)))))) > > -;; (if (and .title .body) > > +;; (if (and .title.0 .body) > > ;; .body > > ;; .site > > ;; .site.contents)) > > @@ -93,14 +94,17 @@ let-alist--access-sexp > > (if (string-match "\\`\\." name) > > clean > > (let-alist--list-to-sexp > > - (mapcar #'intern (nreverse (split-string name "\\."))) > > + (mapcar #'read (nreverse (split-string name "\\."))) > > variable)))) > > > > (defun let-alist--list-to-sexp (list var) > > "Turn symbols LIST into recursive calls to `cdr' `assq' on VAR." > > - `(cdr (assq ',(car list) > > - ,(if (cdr list) (let-alist--list-to-sexp (cdr list) var) > > - var)))) > > + (let ((sym (car list)) > > + (rest (if (cdr list) (let-alist--list-to-sexp (cdr list) var) > > + var))) > > + (cond > > + ((numberp sym) `(nth ,sym ,rest)) > > + (t `(cdr (assq ',sym ,rest)))))) > > > > (defun let-alist--remove-dot (symbol) > > "Return SYMBOL, sans an initial dot." > > @@ -116,22 +120,23 @@ let-alist > > "Let-bind dotted symbols to their cdrs in ALIST and execute BODY. > > Dotted symbol is any symbol starting with a `.'. Only those present > > in BODY are let-bound and this search is done at compile time. > > +A number will result in a list index. > > > > For instance, the following code > > > > (let-alist alist > > - (if (and .title .body) > > + (if (and .title.0 .body) > > .body > > .site > > .site.contents)) > > > > essentially expands to > > > > - (let ((.title (cdr (assq \\='title alist))) > > + (let ((.title (nth 0 (cdr (assq \\='title alist)))) > > (.body (cdr (assq \\='body alist))) > > (.site (cdr (assq \\='site alist))) > > (.site.contents (cdr (assq \\='contents (cdr (assq \\='site > alist)))))) > > - (if (and .title .body) > > + (if (and .title.0 .body) > > .body > > .site > > .site.contents)) > --000000000000c0399b06224727f8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi all,

The patch looks good.
Stefan= , would you mind applying it? (It'll take a while for me to get everyth= ing configured.)

best,
Ar= tur


On Tue, 10 Sept 2024 at 20:22, Stefan Kangas <<= a href=3D"mailto:stefankangas@gmail.com">stefankangas@gmail.com> wro= te:
Artur, do yo= u have any thoughts on the below patch?

Spencer Baugh <sbaugh@janestreet.com> writes:

> From 28e52a343f72dddd991cafd23fea910cc5f64ac5 Mon Sep 17 00:00:00 2001=
> From: Spencer Baugh <sbaugh@janestreet.com>
> Date: Thu, 12 Oct 2023 18:01:46 -0400
> Subject: [PATCH] Support numeric indexing in let-alist
>
> let-alist is very useful.=C2=A0 But sometimes an alist contains a list= in
> the middle, which contains yet more alists.=C2=A0 Previously, this was=
> somewhat painful to deal with, and required something like:
>
> (let-alist alist
>=C2=A0 =C2=A0(let-alist (nth 0 .a)
>=C2=A0 =C2=A0 =C2=A0(let-alist (nth 3 .b)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 .c)))
>
> Now, the following works:
>
> (let-alist alist
>=C2=A0 =C2=A0.a.0.b.3.c)
>
> * lisp/emacs-lisp/let-alist.el (let-alist--access-sexp): Properly
> parse numbers.
> (let-alist--list-to-sexp): Use nth to handle numbers.
> (let-alist): Update docs.
> ---
>=C2=A0 lisp/emacs-lisp/let-alist.el | 25 +++++++++++++++----------
>=C2=A0 1 file changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/lisp/emacs-lisp/let-alist.el b/lisp/emacs-lisp/let-alist.= el
> index d9ad46b2af7..de7c087bf2a 100644
> --- a/lisp/emacs-lisp/let-alist.el
> +++ b/lisp/emacs-lisp/let-alist.el
> @@ -36,22 +36,23 @@
>=C2=A0 ;; symbol inside body is let-bound to their cdrs in the alist.= =C2=A0 Dotted
>=C2=A0 ;; symbol is any symbol starting with a `.'.=C2=A0 Only thos= e present in
>=C2=A0 ;; the body are let-bound and this search is done at compile tim= e.
> +;; A number will result in a list index.
>=C2=A0 ;;
>=C2=A0 ;; For instance, the following code
>=C2=A0 ;;
>=C2=A0 ;;=C2=A0 =C2=A0(let-alist alist
> -;;=C2=A0 =C2=A0 =C2=A0(if (and .title .body)
> +;;=C2=A0 =C2=A0 =C2=A0(if (and .title.0 .body)
>=C2=A0 ;;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0.body
>=C2=A0 ;;=C2=A0 =C2=A0 =C2=A0 =C2=A0.site
>=C2=A0 ;;=C2=A0 =C2=A0 =C2=A0 =C2=A0.site.contents))
>=C2=A0 ;;
>=C2=A0 ;; essentially expands to
>=C2=A0 ;;
> -;;=C2=A0 =C2=A0(let ((.title (cdr (assq 'title alist)))
> +;;=C2=A0 =C2=A0(let ((.title.0 (nth 0 (cdr (assq 'title alist))))=
>=C2=A0 ;;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(.body=C2=A0 (cdr (assq '= ;body alist)))
>=C2=A0 ;;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(.site=C2=A0 (cdr (assq '= ;site alist)))
>=C2=A0 ;;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(.site.contents (cdr (assq &= #39;contents (cdr (assq 'site alist))))))
> -;;=C2=A0 =C2=A0 =C2=A0(if (and .title .body)
> +;;=C2=A0 =C2=A0 =C2=A0(if (and .title.0 .body)
>=C2=A0 ;;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0.body
>=C2=A0 ;;=C2=A0 =C2=A0 =C2=A0 =C2=A0.site
>=C2=A0 ;;=C2=A0 =C2=A0 =C2=A0 =C2=A0.site.contents))
> @@ -93,14 +94,17 @@ let-alist--access-sexp
>=C2=A0 =C2=A0 =C2=A0 (if (string-match "\\`\\." name)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 clean
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (let-alist--list-to-sexp
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0(mapcar #'intern (nreverse (split-stri= ng name "\\.")))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0(mapcar #'read (nreverse (split-string= name "\\.")))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0variable))))
>
>=C2=A0 (defun let-alist--list-to-sexp (list var)
>=C2=A0 =C2=A0 "Turn symbols LIST into recursive calls to `cdr'= `assq' on VAR."
> -=C2=A0 `(cdr (assq ',(car list)
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ,(if (cdr list) (let= -alist--list-to-sexp (cdr list) var)
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0var))))=
> +=C2=A0 (let ((sym (car list))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 (rest (if (cdr list) (let-alist--list-to-= sexp (cdr list) var)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0var)))<= br> > +=C2=A0 =C2=A0 (cond
> +=C2=A0 =C2=A0 =C2=A0((numberp sym) `(nth ,sym ,rest))
> +=C2=A0 =C2=A0 =C2=A0(t `(cdr (assq ',sym ,rest))))))
>
>=C2=A0 (defun let-alist--remove-dot (symbol)
>=C2=A0 =C2=A0 "Return SYMBOL, sans an initial dot."
> @@ -116,22 +120,23 @@ let-alist
>=C2=A0 =C2=A0 "Let-bind dotted symbols to their cdrs in ALIST and = execute BODY.
>=C2=A0 Dotted symbol is any symbol starting with a `.'.=C2=A0 Only = those present
>=C2=A0 in BODY are let-bound and this search is done at compile time. > +A number will result in a list index.
>
>=C2=A0 For instance, the following code
>
>=C2=A0 =C2=A0 (let-alist alist
> -=C2=A0 =C2=A0 (if (and .title .body)
> +=C2=A0 =C2=A0 (if (and .title.0 .body)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .body
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 .site
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 .site.contents))
>
>=C2=A0 essentially expands to
>
> -=C2=A0 (let ((.title (cdr (assq \\=3D'title alist)))
> +=C2=A0 (let ((.title (nth 0 (cdr (assq \\=3D'title alist))))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (.body=C2=A0 (cdr (assq \\=3D'bo= dy alist)))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (.site=C2=A0 (cdr (assq \\=3D'si= te alist)))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (.site.contents (cdr (assq \\=3D'= ;contents (cdr (assq \\=3D'site alist))))))
> -=C2=A0 =C2=A0 (if (and .title .body)
> +=C2=A0 =C2=A0 (if (and .title.0 .body)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .body
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 .site
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 .site.contents))
--000000000000c0399b06224727f8--