help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Example use of macro to minimize and generalize the code


From: Michael Heerdegen
Subject: Re: Example use of macro to minimize and generalize the code
Date: Tue, 01 Jun 2021 01:37:28 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Jean Louis <bugs@gnu.support> writes:

> (defmacro when-tabulated-id (table id &rest body)
>   (declare (indent 2) (debug t))
>   (ignore id)
>   `(if id
>        (progn
>        ,@body)
>      (if (or (eq ,table 'any)
>            (string-equal ,table rcd-current-table))
>        (let ((id (tabulated-list-get-id)))
>          (if id
>              (progn ,@body)
>            (message "Did not get ID")))
>        (message "This function is for table `%s' only" ,table))))

There is something wrong with that definition however: the variable `id'
is completely ignored, specifying something at that argument position is
redundant.

Tt may "work" by accident if the symbol `id' happens to be dynamically
bound to the same thing that you specify as argument, but only when that
exact variable name is used and only in dynamically binding Lisp.
Normally the byte compiler warns about this kind of problem - of course
only if you don't silence it ;-)

Michael.




reply via email to

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