From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Thuna Newsgroups: gmane.emacs.bugs Subject: bug#72344: [PATCH] Add a version of cl-once-only which handles lists of forms Date: Mon, 29 Jul 2024 21:54:48 +0200 Message-ID: <87plqw0y9j.fsf@gmail.com> References: <87y15l1aj8.fsf@gmail.com> <8734nsk72i.fsf@melete.silentflame.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7090"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 72344@debbugs.gnu.org To: Sean Whitton Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jul 29 21:57:03 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 1sYWUP-0001bo-CL for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 29 Jul 2024 21:57:01 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sYWUE-0008RH-CB; Mon, 29 Jul 2024 15:56:50 -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 1sYWUD-0008Qv-7B for bug-gnu-emacs@gnu.org; Mon, 29 Jul 2024 15:56:49 -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 1sYWUC-0005U8-UB for bug-gnu-emacs@gnu.org; Mon, 29 Jul 2024 15:56:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=h1NwwleAFh4TMlDPLRwIeIvPbx9cSlD6NtrcThHCFd8=; b=C582Ow58HWeqfOW4I3AWAvFnX6hdhiZccHjQQp3Fis1VBzRPtw9+HMdVsX+4bAftfiFxHZH1XuAuFhkfrahbSZvXDrBE/TdvyoyqztzRGbnNPISm3UHxbdDSvE5geU/GJv9lrNo5k30nLPGDc/Cs5wdTbN+9QevNVn3PfWyQmP1CPrfc1bEEDAmDTqZ2CyD1TQ86iHAfx/JIKDa20PRhDIqweUMWV1WUzaxtjGhjVXgSxKo91wRbS/cj4B553ncj+Jt6HJEBdux6lKOADoMftjkD/9q8/BwCLmbVwzkeyjGqGT1U9QviOffdO/JUMSQ0relI20le9y3F/YR64yQP1A==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sYWUQ-0005Nu-01 for bug-gnu-emacs@gnu.org; Mon, 29 Jul 2024 15:57:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Thuna Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 29 Jul 2024 19:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72344 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 72344-submit@debbugs.gnu.org id=B72344.172228296820633 (code B ref 72344); Mon, 29 Jul 2024 19:57:01 +0000 Original-Received: (at 72344) by debbugs.gnu.org; 29 Jul 2024 19:56:08 +0000 Original-Received: from localhost ([127.0.0.1]:46397 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sYWTX-0005Mi-VZ for submit@debbugs.gnu.org; Mon, 29 Jul 2024 15:56:08 -0400 Original-Received: from mail-ed1-f41.google.com ([209.85.208.41]:60742) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sYWTV-0005Ma-J6 for 72344@debbugs.gnu.org; Mon, 29 Jul 2024 15:56:06 -0400 Original-Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5a20de39cfbso5658640a12.1 for <72344@debbugs.gnu.org>; Mon, 29 Jul 2024 12:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722282890; x=1722887690; darn=debbugs.gnu.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=h1NwwleAFh4TMlDPLRwIeIvPbx9cSlD6NtrcThHCFd8=; b=QXYV+Vgfw/qG6DNHTLpJn5nUEkal8E/zYDlnckfukQefi64sThfyd1+WgGzcHjtvT3 Wz6GUmfSj/blszoplVOFGTN5ANQEGEHUaJKWU1lOCyWh3cmgTtH17MjM1yOluk10gvtw gA1vNg4zrchbuUTWBI8ZA0AwNcOu+dO8k21oGSgVpMZbVS89MQ47z38DHnfhHNAIo9BW OS4tX3myWeWw/6XKZMsfu00aWKUbl+JdgvfzZ9g/SJyl+yWwiZhtNRZ07Vt/Ynmq61Wi lsCZmb23DIPiWM+DVUzil42wwd3bbsoA5zdLHEN5lnQQvB5rIxSSqFI8SHp01qC5B/lF 7tIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722282890; x=1722887690; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=h1NwwleAFh4TMlDPLRwIeIvPbx9cSlD6NtrcThHCFd8=; b=RcX0eti/S9kDaFJwTzdyiNqSUgDS3tOUYMEI3QHE+D+Kh5xiMr3ECq8yxthNOcWthA cJ4jBVbb8C5lyBAhOYInNleeIn0dHJw65w3xvhrcAIqdzuyoT5pIX+aPqb17/0Hht/V4 EcCQRZy3KEXoxBS0k6sdNHb/m3YPQGDDqitqF7gRVxWqDvMGYVW3hzeOsCEMhbihTsLS LVb4bFdUt2Yo7UtZqaeh6gO5FpaQkJwWvrxvE5Ey2J4C1OBv4UFoGEZXDvo0Ka0JvI/R J9uVo90TnFbyuLtkgdaxSrL24RQde06R8wodEoSDFCHF3/JJIDyv6w5P6EyYsJnD3n3H eS+g== X-Gm-Message-State: AOJu0Ywe8IOHQBT9rplH35GK5sd+l3G9Y1UKTxQMrZ5OlA5EAoSBaKsu KDSlOmmy58TAK70i7r37q5SMpP0uBNlhcMlTGYSs3QvkX9+xGdUHpo9aVHV47vI= X-Google-Smtp-Source: AGHT+IFq62WVJ3BU51iRvSRrVqTHocFw24vfpNeX5/g7DxYqs49FJUpu62RckK86kX3EfegYKfQvDw== X-Received: by 2002:a17:907:c50a:b0:a77:a630:cf89 with SMTP id a640c23a62f3a-a7d3fa3c67cmr608597066b.0.1722282889954; Mon, 29 Jul 2024 12:54:49 -0700 (PDT) Original-Received: from thuna-lis3 ([85.106.105.81]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acad41b30sm545000866b.111.2024.07.29.12.54.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 12:54:49 -0700 (PDT) In-Reply-To: <8734nsk72i.fsf@melete.silentflame.com> 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:289536 Archived-At: > To be honest, cl-once-only* seems quite esoteric. Could you perhaps > show me a direct comparison between some cl-once-only code and how it is > made more readable by cl-once-only*? That seems to me to be the key > criteria. `cl-once-only*' is meant to work in situations where `cl-once-only' does not, namely a situation where you do not know the number of forms to be evaluated. While such a situation *could* exist without, the cases which benefit from `cl-once-only*' are overwhelmingly likely to be of the (defmacro _ (control &rest args) `(progn (do-something-with-control ,@args) (foo ,@args))) variety. The problem here is that the forms in ARGS will be evaluated twice while we only want it to happen once. An alternative way to achieve this would be to do (defmacro _ (control &rest args) (cl-with-gensyms (argslist) `(let ((,argslist (list ,@args))) ...))) and either let-bind ARGS to ARGSLIST or only refer to ARGSLIST within the body, keeping in mind that ARGSLIST is only a symbol during macroexpansion and that in order to refer to individual arguments you need to do (nth N ,ARGSLIST) such that the expanded code itself finds the relevant argument among all the ones. With `cl-once-only*', ARGSLIST (or rather ARGS) is not a symbol but a list of symbols so to refer to the individual argument you do ,(nth N ARGS) and you can simply wrap your macro which worked (sans the double evaluating) without the `cl-once-only*' and it should simply* work out of the box. (* There is a problem with, say, checking `macroexp-const-p' on the given arguments, but that is not something that is too difficult to correct, within reason, and `cl-once-only' doesn't do it either so I don't think it matters too much.) > Also, I wonder if a name like cl-list-once-only would be better. I don't necessarily think that that name is bad but it doesn't quite get to the heart of the macro either. The macro is meant to be a `cl-once-only' which works on a list of forms, and I feel that the "of forms" part is more important than the "list" part, which is conceptually more likely to take on a meaning of some ambiguous "collection" rather than a chain of cons cells.