From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#72344: [PATCH] Add a version of cl-once-only which handles lists of forms Date: Wed, 14 Aug 2024 09:09:04 +0300 Message-ID: <86mslffxfj.fsf@gnu.org> References: <87y15l1aj8.fsf@gmail.com> <8734nsk72i.fsf@melete.silentflame.com> <87plqw0y9j.fsf@gmail.com> <87ikwi5neo.fsf@melete.silentflame.com> <871q35mdrd.fsf@gmail.com> <871q321l7d.fsf@melete.silentflame.com> <874j7xzvgx.fsf@gmail.com> <87r0b1su7p.fsf@melete.silentflame.com> <874j7o2kcq.fsf@gmail.com> <87zfpg3r4q.fsf@melete.silentflame.com> <87v80326ab.fsf@gmail.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34626"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 72344@debbugs.gnu.org, spwhitton@spwhitton.name To: Thuna Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 14 08:12:01 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 1se7En-0008qg-5Q for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 14 Aug 2024 08:12:01 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1se7EJ-0002He-Ir; Wed, 14 Aug 2024 02:11:31 -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 1se7EG-0002H0-SR for bug-gnu-emacs@gnu.org; Wed, 14 Aug 2024 02:11:29 -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 1se7EG-0007oq-KF for bug-gnu-emacs@gnu.org; Wed, 14 Aug 2024 02:11:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:From:Date:To:Subject; bh=LQ/EFdomSb1g/FgQRMhx+Fxzzfxq7X/a5roPSbfS45c=; b=CteVMlI3uWAwvohd4edhizBtJJCa3dFItpdZXqtPn+FWm4Xgu039htSWl76HgnIgiIXYtdBGWEOgwzfjN38inl+xmh1FYUa96p/343ov3QcjjfRyPmpmtJXbKwKSrJsE1WGVWUIjoCakhXaiDEm/HrIjOoe109e2ilyhmdpqeVoa7TLgrVp9uHUdDqRqodjXN4Bary933WlOI2l9LQz5HGbI7m3HpenGkAS4LwuFjMeP9k5DCwUCZThkvxmiaDkfRewXM3L0TBj7jdNecYYhX9slQoUYvvCFucy3wxmIe9xPBhmGAQRHKHGMkRN9sEPmoSmMeA2WZOB5Kjhzq8h23Q==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1se7Eo-000144-GU for bug-gnu-emacs@gnu.org; Wed, 14 Aug 2024 02:12:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 14 Aug 2024 06:12:02 +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.17236159214085 (code B ref 72344); Wed, 14 Aug 2024 06:12:02 +0000 Original-Received: (at 72344) by debbugs.gnu.org; 14 Aug 2024 06:12:01 +0000 Original-Received: from localhost ([127.0.0.1]:45867 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1se7Em-00013p-LD for submit@debbugs.gnu.org; Wed, 14 Aug 2024 02:12:01 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:34644) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1se7El-00013Z-4b for 72344@debbugs.gnu.org; Wed, 14 Aug 2024 02:12:00 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1se7C0-0007Qp-Im; Wed, 14 Aug 2024 02:09:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=LQ/EFdomSb1g/FgQRMhx+Fxzzfxq7X/a5roPSbfS45c=; b=b0w2BLwa9tWd /2656/wG/Xvwked0gAQ/MpuVkYF+EsyYvUCu6WCX26MSHwHT+1iafsSVz1A+ymZ20YPJJWydsV6ko s5qgnxvYiGZWDDv4ahWKOby+PHI4UYkU18dSJnDIhlfQBlwJA2OhKXcZkmW8ferVwf//jQxTT5iMi CV2VIrAlYmGBf2OteBTWNWUgWVrZ1DJavnT73aTb4ZnFqJn57HcDzmu6jWICNCuGDKsGWh8zyRij7 g+cQ3dbcPyUE1HcwghF9kirz9WSVJXkl5+yufd7ZQwhRaVdBELdiy+tnC3ETspIa+Hp7Q6wpObOUM ft05cc+GFt83WuuuJanBTA==; In-Reply-To: <87v80326ab.fsf@gmail.com> (message from Thuna on Wed, 14 Aug 2024 04:21:32 +0200) 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:290114 Archived-At: > Cc: 72344@debbugs.gnu.org > From: Thuna > Date: Wed, 14 Aug 2024 04:21:32 +0200 > > Oops, sorry for the bad patch, I've attached the full diff. Thanks, a few comments about the changes to the manual: > +@defmac cl-once-only* (variable forms) body ^^^^^ Shouldn't this be "forms@dots{}"? or maybe "form@dots{}"? > +This macro is a version of @code{cl-once-only} which takes an > +arbitrarily long list of forms. This macro is primarily meant to be > +used where the number of forms is unknown and thus @code{cl-once-only} > +cannot work, such as those obtained by a @code{&body} argument. The last sentence above needs to be restructured. Perhaps simply move the "such as" part to the end of the previous sentence. > +In a call like @code{(my-list ((pop foo) (cl-incf bar) ...) ...)} the ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Such long expressions should be wrapped in @w{..}, to prevent them from being split between two lines. Also, please use @dots{} instead of a literal "..." to generate ellipsis (it will look better in the printed version of the manual). > +@code{pop} and @code{cl-incf} will be evaluated exactly once, ensuring > +their side effects are not applied twice. This code is however very > +complex, in the same way code not using @code{cl-once-only} is. > + > +Using @code{cl-once-only} is not possible directly due to it expecting > +individual forms which can be evaluated. This can be worked around by > +assigning to a variable @code{`(list ,@@vars)} which @emph{can} be > +evaluated: > + > +@example > +(defmacro my-list (vals &rest forms) > + (cl-once-only ((vals `(list ,@@vals))) > + `(list (cl-first ,vals) > + (cl-second ,vals) > + ,vals ; Does not splice > + (progn ,@@forms)))) > +@end example > + > +There are two problems which both result from the fact that @code{vals} > +is not a list inside the body of @code{cl-once-only}: 1. @code{vals} > +cannot be spliced in the way it can in the previous example and > +2. accessing individual elements of @code{vals} can only be done by > +accessing the resulting list @emph{during evaluation}. Compare this to > +the example using @code{cl-once-only*}: Please replace "1. " and "2. " with "First, " and "Second, ", respectively. Alternatively, if you really want a numbered list, you could use @enumerate @item @code{vals} cannot be spliced in the way [...]