[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: |
Eli Zaretskii |
Subject: |
Re: Why shouldn't we have a #if .... #else .... #endif construct in Emacs Lisp? |
Date: |
Sun, 03 Sep 2023 14:02:50 +0300 |
> Date: Sun, 3 Sep 2023 10:48:50 +0000
> Cc: stefankangas@gmail.com, emacs-devel@gnu.org, mattiase@acm.org
> From: Alan Mackenzie <acm@muc.de>
>
> > > 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?
"Evaluation"?
> > > 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.
I tend to agree with "the other party", FWIW.
Re: Why shouldn't we have a #if .... #else .... #endif construct in Emacs Lisp?, Philip Kaludercic, 2023/09/02