all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Why shouldn't we have a #if .... #else .... #endif construct in Emacs Lisp?
@ 2023-08-28 19:37 Alan Mackenzie
  2023-08-28 19:47 ` Ulrich Mueller
                   ` (4 more replies)
  0 siblings, 5 replies; 66+ messages in thread
From: Alan Mackenzie @ 2023-08-28 19:37 UTC (permalink / raw)
  To: emacs-devel

Hello, Emacs.

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

..  This is not actually all that difficult to write.  My first attempt
uses a compiler-macro, and looks like this:

    (defun hash-if (condition if-part &rest else-part)
      "A compiler macro analogous to C's #if.
    CONDITION is evaluated at compile time.  If it is non-nil,
    IF-PART gets compiled.  Otherwise ELSE-PART (enclosed in a
    `progn') gets compiled."
      (declare (indent 2))
      (error "hash-if has been called directly"))

    (put 'hash-if 'compiler-macro
         (lambda (form condition if-part &rest else-part)
           (if (eval condition lexical-binding)
               if-part
             (cons 'progn else-part))))

..  I propose adding it to subr.el, just before (defmacro when ....).

What do people think about this?

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 66+ messages in thread

end of thread, other threads:[~2023-09-20 12:59 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.