[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: |
Mon, 28 Aug 2023 20:06:27 +0000 |
Hello, Ulrich.
On Mon, Aug 28, 2023 at 21:47:57 +0200, Ulrich Mueller wrote:
> >>>>> On Mon, 28 Aug 2023, Alan Mackenzie wrote:
> > In C, we have the very useful conditional compilation directives
> > introduced by #if or #ifdef, etc., which end at #end.
> > In Emacs Lisp we have no such construct. This is a Bad Thing.
> > More and more, especially recently, irritating warning messages are
> > occurring for, for example, obsolete variables and functions inside
> > conditionals which ensure they aren't used. For example:
> > (when (< emacs-major-version 24)
> > (defadvice .....))
> > produces the warning about defadvice being obsolete. (I haven't actually
> > tested this example). What we really want here is for the defadvice only
> > to be _compiled_ when (< emacs-major-version 24), rather than compiled
> > unconditionally and not run.
> I believe (eval-when-compile (< emacs-major-version 24)) would work?
I've twisted my head into knots in the past trying to work out how to
use eval-when/and-compile for this purpose. The point is, I don't want
the defadvice to be evaluated at compile time; I just want it to be
compiled (or not).
> > I propose a new function, hash-if, which would do what we want. The
> > above example could then be written something like:
> > (hash-if (< emacs-major-version 24)
> > (defadvice .....)
> > (advice-add .....))
> But the old Emacs version wouldn't have the function, so it couldn't be
> used like this. What am I missing?
That's a very good point. I would propose that we suggest to package
maintainers that they include the entire source of hash-if inside a
suitable conditional in their packages. It's only 13 lines of code,
including a doc string.
It would appear that the compiler-macro mechanism existed at the latest
in Emacs 21.4. I don't know how well it worked in these earlier
versions.
--
Alan Mackenzie (Nuremberg, Germany).
Re: Why shouldn't we have a #if .... #else .... #endif construct in Emacs Lisp?, Emanuel Berg, 2023/08/28