Wrong Time

The most common problem in writing macros is doing some of the real work prematurely—while expanding the macro, rather than in the expansion itself. For instance, one real package had this macro definition:

(defmacro my-set-buffer-multibyte (arg)
  (if (fboundp 'set-buffer-multibyte)
      (set-buffer-multibyte arg)))

With this erroneous macro definition, the program worked fine when interpreted but failed when compiled. This macro definition called set-buffer-multibyte during compilation, which was wrong, and then did nothing when the compiled package was run. The definition that the programmer really wanted was this:

(defmacro my-set-buffer-multibyte (arg)
  (if (fboundp 'set-buffer-multibyte)
      `(set-buffer-multibyte ,arg)))

This macro expands, if appropriate, into a call to set-buffer-multibyte that will be executed when the compiled program is actually run.

Copyright © 1990-1996, 1998-2021 Free Software Foundation, Inc.
Licensed under the GNU GPL license.
https://www.gnu.org/software/emacs/manual/html_node/elisp/Wrong-Time.html