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

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

Re: Problem when run-hook-with-args with closure


From: Stefan Monnier
Subject: Re: Problem when run-hook-with-args with closure
Date: Fri, 19 Dec 2014 09:11:45 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

>   (setq foo
>         (lambda (y)
>           (message "x+y=%d" (+ x y)))))
> (run-hook-with-args 'foo 1)

Hooks should contain *lists* of functions.  The fact that they can also
just contain a function is an old backward compatibility hack: better
not rely on it.

So, if you do it right, you won't hit the bug:

     (setq foo
           (list (lambda (y)
                   (message "x+y=%d" (+ x y))))))
   (run-hook-with-args 'foo 1)

Or better yet:

     (add-hook 'foo
               (lambda (y)
                   (message "x+y=%d" (+ x y))))))
   (run-hook-with-args 'foo 1)


-- Stefan




reply via email to

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