emacs-devel
[Top][All Lists]
Advanced

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

Re: Idempotency of add-hook wrt lambda expressions


From: xah lee
Subject: Re: Idempotency of add-hook wrt lambda expressions
Date: Wed, 4 Mar 2009 12:13:08 -0800

On Wed, Mar 4, 2009 at 6:18 AM, Stefan Monnier <address@hidden> wrote:
> Say a file contains an add-hook form with a lambda argument:
>   (add-hook 'foo-mode (lambda () (bar)))
> Annoyingly, the function will be added to the hook twice if the file
> is byte compiled, loaded, then reevaluated (such as with eval-buffer).

As a general rule, you should not put a lambda but a function name
(i.e. a symbol) instead, to avoid all those problems (and be able to
replace the function with a newer version of it).  But occasionally
a lambda is really exactly what you want, of course.

i prefer this be transparent to the user as Geoff Gole suggested.

My reason is that from a user point of view, lambda serves the same purpose as function name, and one less thing to worry about problems that might come from byte compiling.

if the code suggested does fix this without any other problems,  why not?

cheers,

  Xah

reply via email to

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