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: Thu, 31 Aug 2023 07:50:23 +0000

Hello, Richard.

On Wed, Aug 30, 2023 at 22:07:04 -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. ]]]

>   > >     (when (eval-when-compile (< emacs-major-version 24))
>   > >       (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.

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.  Also, it is possible for the condition to
be dependent upon a minor version number, maybe.

Why do you think a more restricted test of the version number would be
better than a more general test?

The changes to the code to convert from `if' to `hash-if' (or
`static-if' as has been proposed) are minor - they just need amending
the if/when/unless forms to hash-if.  Also, there will not be all that
many of them.  That way, we have more flexibility than testing just the
major version number.

> That will handle `when' and `unless', since they expand into `if'.

> It may be necessary to implement this in two places, one for inside of
> function bodies and one for top level (outside of function
> definitions).  But the code for this should be so short that having
> two is hardly much loss.

The macro hash-if itself is very short, the current version taking 13
lines (including doc string), including a condition-case checking for
`eval' having only one parameter.  The idea is that a package maintainer
can copy this directly into her source code (inside an (if (not (fboundp
'hash-if)) ....)) so the mechanism will work also in older Emacsen.

> -- 
> 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).



reply via email to

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