Spencer Baugh <sbaugh@HIDDEN>
to control <at> debbugs.gnu.org
.
Full text available.Stefan Kangas <stefankangas@HIDDEN>
to control <at> debbugs.gnu.org
.
Full text available.Received: (at 66509) by debbugs.gnu.org; 12 Oct 2023 22:04:31 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Thu Oct 12 18:04:31 2023 Received: from localhost ([127.0.0.1]:44408 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1qr3nD-0007Cu-7d for submit <at> debbugs.gnu.org; Thu, 12 Oct 2023 18:04:31 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:60919) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <sbaugh@HIDDEN>) id 1qr3nA-0007Ca-AT for 66509 <at> debbugs.gnu.org; Thu, 12 Oct 2023 18:04:30 -0400 From: Spencer Baugh <sbaugh@HIDDEN> To: 66509 <at> debbugs.gnu.org Subject: Re: bug#66509: 29.1.50; let-alist should support numeric indexing In-Reply-To: <iera5sn5wid.fsf@HIDDEN> (Spencer Baugh's message of "Thu, 12 Oct 2023 18:03:22 -0400") References: <iera5sn5wid.fsf@HIDDEN> Date: Thu, 12 Oct 2023 18:04:00 -0400 Message-ID: <ier7cnr5whb.fsf@HIDDEN> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Support-numeric-indexing-in-let-alist.patch X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 66509 X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) From 28e52a343f72dddd991cafd23fea910cc5f64ac5 Mon Sep 17 00:00:00 2001 From: Spencer Baugh <sbaugh@HIDDEN> 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)) -- 2.39.3
bug-gnu-emacs@HIDDEN
:bug#66509
; Package emacs
.
Full text available.Received: (at submit) by debbugs.gnu.org; 12 Oct 2023 22:03:59 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Thu Oct 12 18:03:59 2023 Received: from localhost ([127.0.0.1]:44403 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1qr3mg-0007BD-Mf for submit <at> debbugs.gnu.org; Thu, 12 Oct 2023 18:03:59 -0400 Received: from lists.gnu.org ([2001:470:142::17]:34572) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <sbaugh@HIDDEN>) id 1qr3mb-0007Ax-AF for submit <at> debbugs.gnu.org; Thu, 12 Oct 2023 18:03:57 -0400 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 <sbaugh@HIDDEN>) id 1qr3m9-0002jP-5e for bug-gnu-emacs@HIDDEN; Thu, 12 Oct 2023 18:03:25 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <sbaugh@HIDDEN>) id 1qr3m7-0002SH-Nn for bug-gnu-emacs@HIDDEN; Thu, 12 Oct 2023 18:03:24 -0400 From: Spencer Baugh <sbaugh@HIDDEN> To: bug-gnu-emacs@HIDDEN Subject: 29.1.50; let-alist should support numeric indexing Date: Thu, 12 Oct 2023 18:03:22 -0400 Message-ID: <iera5sn5wid.fsf@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=64.215.233.18; envelope-from=sbaugh@HIDDEN; helo=mxout5.mail.janestreet.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.9 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -0.1 (/) It would be nice if let-alist supported indexing. So if my alist contained lists in some places, instead of writing: (let-alist alist (let-alist (nth 0 .a) (let-alist (nth 3 .b) .c))) I could instead write: (let-alist alist .a.0.b.3.c) A patch which does this to follow.
Spencer Baugh <sbaugh@HIDDEN>
:bug-gnu-emacs@HIDDEN
.
Full text available.bug-gnu-emacs@HIDDEN
:bug#66509
; Package emacs
.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.