From: Alan Mackenzie <acm@muc.de>
To: Richard Stallman <rms@gnu.org>
Cc: ulm@gentoo.org, emacs-devel@gnu.org
Subject: Re: Why shouldn't we have a #if .... #else .... #endif construct in Emacs Lisp?
Date: Mon, 4 Sep 2023 10:50:07 +0000 [thread overview]
Message-ID: <ZPW2X558t42Q2_3O@ACM> (raw)
In-Reply-To: <E1qcyTg-0003aM-Im@fencepost.gnu.org>
Hello, Richard.
On Sun, Sep 03, 2023 at 21:34:08 -0400, Richard Stallman wrote:
> [[[ To any NSA and FBI agents reading my email: please consider ]]]
> [[[ whether defending the US Constitution against all enemies, ]]]
> [[[ foreign or domestic, requires you to follow Snowden's example. ]]]
> > > > > (defadvice .....))
> > > > However, when evaluating the containing defun/defmacro rather than byte
> > > > compiling it, the irritating warning message will appear with the e-w-c
> > > > strategem, but not with hash-if. ;-)
> > > How about making the byte compiler recognize the construct
> > > (if (< emacs-major-version NUMBER) ...)
> > > and do this optimization on it?
> > > I think that will DTRT when compiled and when interpreted,
> > > and it won't require changes in the code of the programs that use it.
> People propose to handle conditions about Emacs version numbers in
> a more optimized way. I proposed a simple syntax for that.
> Isn't it better?
I don't think it is.
> > The conditions we want to test are sometimes/frequently expressed in
> > terms of the (non-)existence of variables, etc. It would be
> > inconvenient for package maintainers to have to determine "critical"
> > Emacs version numbers to use.
> I don't follow you, Haven't we been talking about conditions on Emacs
> versions all along in this discussion? I did not propose that as a
> change, I carried it along.
For example, in CC Mode there is a chunk of code looking like ....
(when (fboundp 'electric-indent-local-mode) ; Emacs 24.4 or later.
(electric-indent-local-mode (if c-electric-flag 1 0)))
, and there are quite a few instances like it. Here, there is a comment
about which versions are relevant, but that is somewhat unusual. Note
here that we would have to test both the major and minor version numbers
to do this correctly.
I intend to replace that code with
(static-if (fboundp 'electric-indent-local-mode) ; Emacs 24.4 or later.
(electric-indent-local-mode (if c-electric-flag 1 0)))
.. (hash-if has been renamed static-if.) It would be more work to
replace it with
(when (or (> emacs-major-version 24)
(and (= emacs-major-version 24)
(>= emacs-minor-version 4)))
(electric-indent-local-mode (if c-electric-flag 1 0)))
, and that's not even taking into account the one-time effort to put
special handling into >, >=, <, <=, =, /= (?etc.) for
emacs-m\(aj\|in\)or-version. I haven't looked into this in any detail,
but it might be quite a lot of work.
> > Why do you think a more restricted test of the version number would be
> > better than a more general test?
> If people would like other tests too, I have nothing against them.
> The issue is how to implement whatever tests we support. If they can
> be done at compiler time, isn't this the better implementation?
static-if is a completely ordinary macro which is 10 lines long
(including doc string), and there's a new section in the elisp manual for
it. Amending the evaluator and byte compiler for special handling for
emacs-m..or-version would be more than 10 lines.
There are currently just 45 occurrences of emacs-major-mode in our Lisp
sources, and most of these are comparisons with a decimal number.
Editing each occurrence by hand to use static-if would still be less work
than amending the evaluator and byte compiler for special handling.
We have just over 2000 occurrences of boundp and fboundp, some of which
will be used to isolate code to be evaluated only when the
variable/function is bound or not bound, as in the above CC Mode snippet.
> I guess I don't follow. Why do you prefer `hash-if' rather
> than this simple compile-time syntax? Why change the syntax rather
> than using the syntax we use now?
Because of the complexity of adding suitable special handling for
emacs-m..nor mode to the evaluator and byte compiler compared with the
simplicity of the new macro, and the relative ease of adapting existing
code.
> --
> Dr Richard Stallman (https://stallman.org)
> Chief GNUisance of the GNU Project (https://gnu.org)
> Founder, Free Software Foundation (https://fsf.org)
> Internet Hall-of-Famer (https://internethalloffame.org)
--
Alan Mackenzie (Nuremberg, Germany).
next prev parent reply other threads:[~2023-09-04 10:50 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-28 19:37 Why shouldn't we have a #if .... #else .... #endif construct in Emacs Lisp? Alan Mackenzie
2023-08-28 19:47 ` Ulrich Mueller
2023-08-28 20:06 ` Alan Mackenzie
2023-08-28 21:01 ` Ulrich Mueller
2023-08-28 21:46 ` Alan Mackenzie
2023-08-31 2:07 ` Richard Stallman
2023-08-31 7:50 ` Alan Mackenzie
2023-09-04 1:34 ` Richard Stallman
2023-09-04 10:50 ` Alan Mackenzie [this message]
2023-09-04 11:02 ` tomas
2023-09-04 15:19 ` Emanuel Berg
2023-09-04 18:57 ` tomas
2023-09-06 0:58 ` Richard Stallman
2023-09-06 0:58 ` Richard Stallman
2023-09-06 7:28 ` Andreas Schwab
2023-09-06 9:31 ` Alan Mackenzie
2023-09-06 9:56 ` Alan Mackenzie
2023-09-09 0:39 ` Richard Stallman
2023-09-09 10:32 ` Ihor Radchenko
2023-09-10 0:22 ` Richard Stallman
2023-09-10 8:36 ` Ihor Radchenko
2023-09-13 23:53 ` Richard Stallman
2023-09-20 12:59 ` Ihor Radchenko
2023-09-05 0:30 ` Why have a #if .... #else .... #endif construct in Emacs Lisp, when we could make the existing code DTRT unchanged? Richard Stallman
2023-09-05 0:41 ` Emanuel Berg
2023-09-08 17:54 ` Emanuel Berg
2023-09-05 4:37 ` tomas
2023-09-05 5:53 ` Ihor Radchenko
2023-09-05 6:28 ` tomas
2023-09-05 11:06 ` Adam Porter
2023-09-05 11:26 ` Lynn Winebarger
2023-09-05 14:11 ` Alan Mackenzie
2023-09-08 1:01 ` Richard Stallman
2023-09-08 2:45 ` Po Lu
2023-09-10 0:24 ` Richard Stallman
2023-09-05 8:14 ` Why shouldn't we have a #if .... #else .... #endif construct in Emacs Lisp? Ulrich Mueller
2023-08-28 19:53 ` Emanuel Berg
2023-08-29 9:19 ` Alan Mackenzie
2023-08-29 10:36 ` João Távora
2023-08-29 11:09 ` Ihor Radchenko
2023-08-29 11:20 ` João Távora
2023-08-30 20:48 ` Sean Whitton
2023-08-30 20:59 ` João Távora
2023-09-02 23:12 ` Stefan Monnier via Emacs development discussions.
2023-09-03 0:18 ` Emanuel Berg
2023-09-03 12:27 ` João Távora
2023-08-29 12:54 ` Philip Kaludercic
2023-08-29 13:23 ` Alan Mackenzie
2023-09-02 23:09 ` Stefan Monnier via Emacs development discussions.
2023-08-29 16:28 ` LdBeth
2023-08-29 20:09 ` Stefan Kangas
2023-08-30 10:31 ` Alan Mackenzie
2023-08-30 17:36 ` Stefan Kangas
2023-08-30 18:03 ` Alan Mackenzie
2023-08-30 18:17 ` Stefan Kangas
2023-09-02 15:06 ` Alan Mackenzie
2023-09-02 15:17 ` Eli Zaretskii
2023-09-02 19:43 ` Alan Mackenzie
2023-09-03 4:42 ` Eli Zaretskii
2023-09-03 10:48 ` Alan Mackenzie
2023-09-03 11:02 ` Eli Zaretskii
2023-09-03 13:24 ` Alan Mackenzie
2023-09-02 19:20 ` Philip Kaludercic
2023-09-02 19:37 ` Stefan Kangas
2023-09-02 19:58 ` Alan Mackenzie
2023-09-04 11:12 ` Lynn Winebarger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZPW2X558t42Q2_3O@ACM \
--to=acm@muc.de \
--cc=emacs-devel@gnu.org \
--cc=rms@gnu.org \
--cc=ulm@gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).