From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Adding with-gensyms and once-only to subr-x Date: Mon, 11 Apr 2022 13:26:12 -0400 Message-ID: References: <87a6crr3gj.fsf@athena.silentflame.com> <877d7vr1uy.fsf@athena.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="27134"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Sean Whitton Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Apr 11 19:27:28 2022 Return-path: Envelope-to: ged-emacs-devel@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 1ndxp1-0006su-1b for ged-emacs-devel@m.gmane-mx.org; Mon, 11 Apr 2022 19:27:27 +0200 Original-Received: from localhost ([::1]:51278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ndxoz-0007vt-Kb for ged-emacs-devel@m.gmane-mx.org; Mon, 11 Apr 2022 13:27:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndxnx-00072a-Mn for emacs-devel@gnu.org; Mon, 11 Apr 2022 13:26:21 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:17392) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndxnv-0001Gz-23 for emacs-devel@gnu.org; Mon, 11 Apr 2022 13:26:20 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 539D04415D3; Mon, 11 Apr 2022 13:26:17 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id B93FD4415D0; Mon, 11 Apr 2022 13:26:15 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1649697975; bh=v8/c9rNZYewxK8bt6Xg77pGRP2n04XYpPqYzpeK/IEE=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=NJQC4Ia0vpkznUXQy03P9i6HMcezxbufYd5sppm/5OhHI/xeGAoyz8ZC5Shfy9zEI C9fQVM31tg7trNlbJm+oQAIi+CtxkFzLh/+IAF6QeiMH8UiEwHPJp3vo149uyNIeyy fRoMjMrhjhS3+NX4LmvLuT8kYStng8n556dWBadzhwW9PjQEq+mrH7VU6ma4YUHjkf WIa9BBI8f9f5+lyIAEhFMgVnh9fVskJFiOARZy2nYVjOlOY+ti0BsH7dpUP/vy1dMr eWAKmTi1QBsE6Xksp7X6NkGKEE5ebERrVJ5X2kyb3tfBnf63GqWriro6QLW6bL2iAh C5p7Wl/heHNjg== Original-Received: from alfajor (modemcable240.145-162-184.mc.videotron.ca [184.162.145.240]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 1E11712014C; Mon, 11 Apr 2022 13:26:14 -0400 (EDT) In-Reply-To: <877d7vr1uy.fsf@athena.silentflame.com> (Sean Whitton's message of "Mon, 11 Apr 2022 10:01:09 -0700") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:288234 Archived-At: >>> Lately I have been finding myself wanting with-gensyms and once-only, >>> two classic macro-writing macros, available in core Elisp. (There is >>> already org-with-gensyms, but it's not in the least bit Org-specific.) >> I think `once-only` is what we (well, I) called `macroexp-let2`. > Ah, thank you for the pointer. > > (macroexp-let2* nil ((foo foo) (bar bar)) FORMS) > > is quite a bit more verbose than (once-only (foo bar) FORMS), however. > So I would be inclined to keep once-only, though reimplemented in terms > of macroexp-let2*. Does that sound reasonable? How 'bout making `macroexp-let2*` accept the shorter form as in the patch below? I'm not in love with the name `macroexp-let2*` but I find the name `once-only` to lack context. So we could consider renaming, but I'd favor making it live in `macroexp.el` (and come with a `macroexp-` prefix). It could be called `macroexp-once-only` or `macroexp-eval-now`, or we could go crazy with names like `macroexp-copyableize`. Stefan diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el index 1420655f1e9..4783e55e057 100644 --- a/lisp/emacs-lisp/macroexp.el +++ b/lisp/emacs-lisp/macroexp.el @@ -636,12 +636,20 @@ macroexp-let2 (defmacro macroexp-let2* (test bindings &rest body) "Multiple binding version of `macroexp-let2'. -BINDINGS is a list of elements of the form (SYM EXP). Each EXP -can refer to symbols specified earlier in the binding list." +BINDINGS is a list of elements of the form (SYM EXP) or just SYM, +which then stands for (SYM SYM). +Each EXP can refer to symbols specified earlier in the binding list. + +TEST has to be a symbol, and if it is nil it can be omitted." (declare (indent 2) (debug (sexp (&rest (sexp form)) body))) + (when (consp test) ;; `test' was omitted. + (push bindings body) + (setq bindings test) + (setq test nil)) (pcase-exhaustive bindings ('nil (macroexp-progn body)) - (`((,var ,exp) . ,tl) + (`(,(or `(,var ,exp) (and (pred symbolp) ,var (let ,exp var))) + . ,tl) `(macroexp-let2 ,test ,var ,exp (macroexp-let2* ,test ,tl ,@body)))))