unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Thuna <thuna.cing@gmail.com>
To: Sean Whitton <spwhitton@spwhitton.name>
Cc: 72344@debbugs.gnu.org
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	[thread overview]
Message-ID: <87plqw0y9j.fsf@gmail.com> (raw)
In-Reply-To: <8734nsk72i.fsf@melete.silentflame.com>


> 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.





  reply	other threads:[~2024-07-29 19:54 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-28 21:17 bug#72344: [PATCH] Add a version of cl-once-only which handles lists of forms Thuna
2024-07-29  0:39 ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-29 19:30   ` Thuna
2024-07-29 19:54     ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-29  7:09 ` Sean Whitton
2024-07-29 19:54   ` Thuna [this message]
2024-08-03  2:51     ` Sean Whitton
2024-08-03 22:40       ` Thuna
2024-08-06  1:41         ` Sean Whitton
2024-08-06  1:47           ` Sean Whitton
2024-08-09  5:44             ` Sean Whitton
2024-08-06 12:28           ` Thuna
2024-08-06 12:37             ` Sean Whitton
2024-08-13 21:17               ` Thuna
2024-08-13 21:36                 ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-13 22:18                   ` Thuna
2024-08-13 22:57                     ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-14  0:01                     ` Sean Whitton
2024-08-14  0:05                 ` Sean Whitton
2024-08-14  2:21                   ` Thuna
2024-08-14  6:09                     ` Eli Zaretskii
2024-08-14 14:14                       ` Thuna
2024-08-14 14:29                         ` Eli Zaretskii
2024-08-15  1:05                           ` Thuna
2024-08-15  6:28                             ` Eli Zaretskii
2024-08-15 15:15                               ` Thuna
2024-08-15 16:20                                 ` Eli Zaretskii
2024-08-19 16:54                                   ` Richard Stallman
2024-08-15 12:38                         ` Sean Whitton
2024-08-15 15:02                           ` Thuna
2024-08-14  9:47                     ` Sean Whitton
2024-08-06 15:52           ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87plqw0y9j.fsf@gmail.com \
    --to=thuna.cing@gmail.com \
    --cc=72344@debbugs.gnu.org \
    --cc=spwhitton@spwhitton.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).