[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: defmacro with built-in gensym declaration and initialization

From: Basil L. Contovounesios
Subject: Re: defmacro with built-in gensym declaration and initialization
Date: Thu, 21 Jan 2021 20:50:52 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

akater <nuclearspace@gmail.com> writes:

> "Basil L. Contovounesios" <contovob@tcd.ie> 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 “once-only” but unlike once-only, macroexp-let2
> also requires a test function which is exactly why I called it “an
> overcomplicated once-only”.

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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]