From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.devel Subject: Re: defmacro with built-in gensym declaration and initialization Date: Thu, 21 Jan 2021 20:50:52 +0000 Message-ID: <875z3qc8ur.fsf@tcd.ie> References: <87bldk6n2l.fsf@gmail.com> <87turbiuvr.fsf@tcd.ie> <878s8n76ih.fsf@gmail.com> <87o8hj9vl9.fsf@tcd.ie> <875z3q6q51.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34005"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: akater Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Jan 21 21:52:53 2021 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 1l2gwm-0008jM-DE for ged-emacs-devel@m.gmane-mx.org; Thu, 21 Jan 2021 21:52:52 +0100 Original-Received: from localhost ([::1]:54874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l2gwl-0007tW-AA for ged-emacs-devel@m.gmane-mx.org; Thu, 21 Jan 2021 15:52:51 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51042) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l2guz-0006Cj-2w for emacs-devel@gnu.org; Thu, 21 Jan 2021 15:51:01 -0500 Original-Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:35267) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l2guw-00018Q-9T for emacs-devel@gnu.org; Thu, 21 Jan 2021 15:51:00 -0500 Original-Received: by mail-wm1-x329.google.com with SMTP id e15so2647003wme.0 for ; Thu, 21 Jan 2021 12:50:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=11n6L5H/9otBOZjCEu00bRzzljOASyiiO1QN+S2aJXg=; b=IUG9Ug3K3s0ghRX7az2J6XCnheOztgmALQWveFHky7YwGQ3j1IQhfpQkhrPaYQzMLe Z7nxFEoAJWw7yqAl83YPj3pgZHAVomsclDzkFfdgacdu30frW5yxKNUg1lPxioFj0m8D QXp+JDm2XI1hY89pJUuMJ/9ZwtI70VzywoZsPuxRM0EDeMX2CzHj9ZnqX2PWx1eB1h+w q0cvXVksUAUQOXIF1Rb4KTQ+gag1q43OiAaCqFx8np3XyhjOzsCfotXVTGkVmnXv4yKy CbXTpxH9XwlMaQsMexf4BqDxi6XoRwW9GUyrbwFw1hgLj7ncvPAHR9E1A9dlRrYfYU5J ZQ6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=11n6L5H/9otBOZjCEu00bRzzljOASyiiO1QN+S2aJXg=; b=o19pATPWco1l5q5pWlXC0QVTaj2jWO7uvwBqeinHPzYdDwdk1A9XITuO6GFHYsv8pi in86kgvO09j+wNJFYw1lKx9bacTdqneAZ/HUBoECEK4m8gI3w3PWYjRS2sJ2IQHkP5e/ fiQVJkHTYhtuOitQIiJOCmNYZEVMLVmeZqBY6L3TG22+Z6KkasaGIKDLy6RyDf/ve7SU AcLwlzOLnmqntnb5temQ3peyh0iXLe8KqNADsNLuYLOkNbIL8YfvAuI/nCoMnrxQ7baI aC+z5WtE7oVDHBMM/QHIvxrkOapwvFrxj6kepYNvBd5zLkWC2FYgFyZJ5Yopfl0ALg1V txgw== X-Gm-Message-State: AOAM530QaWcB01BmGZkvYwUxoIYNeKKc+cZdcgfY8XwqEpjFnZwm18UW 2WY5ZVeFnS63jTYeJFRkLS6KAkCr0oCIVKym X-Google-Smtp-Source: ABdhPJx5/eP7coBYNlrqWHhxbGwy6QNYjxz4Z3ImHLb5XNd4B284N6RVPvJH4/iCjfkGmLuJXkDpbw== X-Received: by 2002:a1c:149:: with SMTP id 70mr980931wmb.165.1611262254636; Thu, 21 Jan 2021 12:50:54 -0800 (PST) Original-Received: from localhost ([2a02:8084:20e2:c380:d15:339e:aa10:60f1]) by smtp.gmail.com with ESMTPSA id d16sm7615744wrr.59.2021.01.21.12.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jan 2021 12:50:54 -0800 (PST) In-Reply-To: <875z3q6q51.fsf@gmail.com> (akater's message of "Thu, 21 Jan 2021 19:34:02 +0000") Received-SPF: none client-ip=2a00:1450:4864:20::329; envelope-from=contovob@tcd.ie; helo=mail-wm1-x329.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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:263254 Archived-At: akater writes: > "Basil L. Contovounesios" writes: > >> Let's just say I would sooner see native arglists gain support for >> keyword arguments ;). >> >> For non-native arglists, we could always extend cl-defmacro or some >> other definition definer. > > Sorry, I suspect I misunderstood. What's a native arglist? Doesn't > defmacro already have native support for &optional and &rest keywords? Yes, and that's what I mean by native arglists - the ones possessed by built-in C objects such as subroutines, lambda expressions, compiled code, dynamic module functions, etc. and used by built-in C functions such as funcall. By contrast, cl-defmacro, other CL compatibility definitions, etc. have to parse a plain Elisp arglist for CL-specific features like &aux. >> I was referring to the arity of the macro being defined, not that of >> defmacro. > > I guess I'm confused, again. The arity of macro being defined remains > exactly the same. See the --partition-by example in the original > message. defmacro/&gensym is a drop-in replacement; it doesn't change > any arities. Yes, I understood that. Here's what I said: > IMO, this minor convenience is insufficient motivation for > conflating/complicating a macro's global arglist, i.e. its arity, ^^^^^^^^^^^^^^^^^^^^^^^ > calling convention, etc., with utilities for its local body. The bottom line is that argument lists are for arguments, i.e. the public contract between the caller and the callee. Local variables are not part of this contract, so putting them there is misguided, to put it politely, especially if the only motivation is to save a few keystrokes. I suspect that adding support for something like &gensym to native Elisp arglists would amount to a very intrusive change for a very minor convenience (and IMO very unaesthetic anti-pattern). Adding support for something like &gensym to non-native arglists such as those of pcase-lambda, cl-defmacro, etc. would probably be more feasible, but that doesn't necessarily mean we should do it either ;). >> It and its variant macroexp-let2* are relevant wherever the macro author >> wants to avoid evaluating an argument more than once, but improvements >> are always welcome. > > That's usually called =E2=80=9Conce-only=E2=80=9D but unlike once-only, m= acroexp-let2 > also requires a test function which is exactly why I called it =E2=80=9Can > overcomplicated once-only=E2=80=9D. Then why not improve macroexp-let2 and/or provide once-only, like I suggested in my first message, without the need for &gensym? > &gensym is also relevant wherever the macro > author wants to avoid evaluating an argument more than once, and where > the argument needs to be evaluated unconditionally, but it's more > concise, both in terms of token count and nesting depth. One variation > of defmacro/&gensym accessible in the linked repository does perform the > same elimination of bindings as macroexp-let2, only it uses a hardcoded > test function, namely macroexp-const-p. > >>> Since we're moving to >>> natively compiled Elisp, I was thinking it's going to become less >>> relevant in near future, and &gensym covers most use cases of once-only. >> >> I don't see how native compilation changes how existing and new Elisp >> macros ought to be written. > > What's the purpose of TEST in macroexp-let2, then, other than to > minimise bindings in the expansion? (Which I presume is only relevant > when Elisp's byte compiler is used to compile the expanded form.) As you say, it's relevant whenever you want to minimise bindings in the expansion. I still don't see the relation with native compilation. --=20 Basil