In case anyone is still not clear on why quoting lambda expressions is
a good thing, consider the following snippet of code:
(add-hook 'foo-hook
(lambda ()
(let ((i 1))
(setq foo-map (make-sparse-keymap))
(while (< i 4)
(define-key foo-map
(intern (format "button-%d" i)) nil)
(incf i)))))
(add-hook 'foo1-hook
'(lambda ()
(let ((i 1))
(setq foo-map (make-sparse-keymap))
(while (< i 4)
(define-key foo-map
(intern (format "button-%d" i)) nil)
(incf i)))))
After bytecoompiling and loading do:
foo-hook
=> (#<compiled-function nil "...(43)" [1 i make-sparse-keymap foo-map 4
define-key intern format "button-%d" nil] 7>)
foo1-hook
=> ((lambda nil (let ((i 1)) (setq foo-map (make-sparse-keymap)) (while (< i 4)
(define-key foo-map (intern (format "button-%d" i)) nil) (incf i)))))
Note that quoting lambda prevents the bytecompiler from bytecompiling it.
Hrvoje Niksic <hniksic(a)srce.hr> writes:
> The Great Erik Naggum sayeth:
> oh, my advice here was limited to Emacs Lisp. since the Emacs Lisp byte
> code object doesn't identity itself (I have tried to make it do that, so
> error messages would be a little easier on the programmer and user), it
> is much more convenient with named functions.
It would probably be doable with XEmacs and its compiled-function
objects, but Erik is too self-contained to look at XEmacs without
ranting.
I can't try to duplicate his work because he didn't specify
what he
meant by "byte code object identifying itself".
I'm not sure either, but I know that it is inconvenient attempting to
identify where an error came from in a bytecompiled lambda expression
on a hook.
> also, using anonymous functions in hooks is a bad idea since
they
> are hard to remove. binding a key to an anonymous (and
> interactive) function is equally a bad idea.
One point being you can't just evaluate the hook variable in
*scratch*, modify something and reevalute it -- it'll puke on the
un(lisp)readable bytecode object.
It does, but in the specific NEWS example it looks better to use the
anonymous function than to cons up a new function only for that
purpose.
Yup. Just what is gdb-highlight doing in NEWS anyway? Or do I want
to know?