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

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

Re: elisp macros problem


From: David Kastrup
Subject: Re: elisp macros problem
Date: 27 Jul 2004 09:14:52 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

Lowell Kirsh <address@hidden> writes:

> This still doesn't seem to work. With the following defun and call:
> 
> (defmacro my-add-hooks (hooks &rest body)
>    `(dolist (hook ',hooks)
>       (my-add-hook hook ,@body)))
> 
> (my-add-hooks (inferior-lisp lisp emacs-lisp lisp-interaction)
>                (imenu-add-to-menubar "Symbols"))
> 
> I get the following macroexpansion, which looks correct to me, but
> doesn't actually do anything:
> 
> (cl-block-wrapper
>   (catch (quote --cl-block-nil--)
>     (let ((--dolist-temp--20870 (quote (inferior-lisp lisp emacs-lisp
>     lisp-interaction)))
>           hook)
>       (while --dolist-temp--20870
>         (setq hook (car --dolist-temp--20870))
>         (my-add-hook hook
>                      (imenu-add-to-menubar "Symbols"))
>         (setq --dolist-temp--20870 (cdr --dolist-temp--20870)))
>       nil)))

That's because my-add-hook is a macro, too, and so you just add stuff
to hook-mode-hook three times.

> > Apart from that, I consider this sort of thing a crock.  What are
> > you hoping to achieve that you would not be better off doing by a
> > proper function instead of a macro?

In short, I still consider this sort of thing a crock, since you'd be
better off using a function instead of a macro.  You are unable to
comprehend what your macros do, and it shows.  Macros are just not
sensible for this sort of thing.  Use functions instead.  You'll need
to use some quotes at the outer level, but you'll understand what
happens.

To fix the above, you'd need to write something like

(defmacro my-add-hooks (hooks &rest body)
   (dolist (hook hooks)
      `(my-add-hook ,hook ,@body)))


-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum


reply via email to

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