emacs-devel
[Top][All Lists]
Advanced

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

Re: Why shouldn't we have a #if .... #else .... #endif construct in Emac


From: Alan Mackenzie
Subject: Re: Why shouldn't we have a #if .... #else .... #endif construct in Emacs Lisp?
Date: Sun, 3 Sep 2023 10:48:50 +0000

Hello, Eli.

On Sun, Sep 03, 2023 at 07:42:13 +0300, Eli Zaretskii wrote:
> > Date: Sat, 2 Sep 2023 19:43:29 +0000
> > Cc: stefankangas@gmail.com, emacs-devel@gnu.org, mattiase@acm.org
> > From: Alan Mackenzie <acm@muc.de>

> > > > ++++
> > > > +** There is now conditional compilation, based on the C language's #if.
> > > > +To use this, see the new macro 'static-if'.

> > > Same here.  Here, it is actually worse: "based on C language's #if"
> > > could be misinterpreted as meaning the implementation is based on #if
> > > in some way.  I would suggest the following text in NEWS:

> > >  ** New macro 'static-if' for conditional byte-compilation of code.
> > >  This macro hides a form from the byte-compiler based on a
> > >  compile-time condition.  This is handy for avoiding byte-compilation
> > >  warnings about code that will never actually run under some
> > >  conditions.

> > static-if actually works for interpreted compilation as well as byte
> > compilation, so I've removed two "byte-"s from your text, leaving:

> > +++
> > ** New macro 'static-if' for conditional compilation of code.
> > This macro hides a form from the compiler based on a compile-time
> > condition.  This is handy for avoiding byte-compilation warnings about
> > code that will never actually run under some conditions.

> What is "interpreted compilation" in Emacs?  I'm aware of only two
> compilers in Emacs: the byte compiler and the native compiler.  So
> when you talk about "the compiler" above, what does that allude to?

I mean the defmacro and defun macros, particularly when invoked by C-M-x,
etc.  Do we have a generic term for these, regardless of whether they are
called interpretatively  or in the context of byte/native compilation?

> > I think it's now ready to commit, except ....

> > I've had some private email which suggested that perhaps static-if
> > should not include the condition-case which copes with an ancient eval
> > from before lexical binding.  I can see some merit in the argument
> > (lexical binding happened in 24.1, I think), but on the other hand, that
> > extreme backwards compatibility doesn't really cost us anything
> > (static-if is just 13 lines of code).

> > What do you think?

> I don't think I understand the issue: it was discussed in private
> email , and you didn't tell enough for me to understand and form an
> opinion.  What do you mean by "condition-case which copes with an
> ancient eval from before lexical binding"?

Sorry.  The idea is that package maintainers can copy the source of
static-if directly into their packages so as to be able to use it in
older Emacsen.

In the code for static-if, there's a call to eval with two
arguments, CONDITION and lexical-binding.  In (very) old versions of
Emacs, eval would only accept one argument, the form.  So in such an old
Emacs, static-if will throw a wrong-number-of-args (or void-variable)
error.

I have proposed catching this error with a condition-case and in the
handler, calling eval again with just one argument.

The other party in the email has opined that static-if should not contain
this condition-case mechanism, and anybody writing for such an old Emacs
should make their own adjustments.

Perhaps it's too small a point to be worth bothering about, but I thought
I'd ask your view anyway.

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

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