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

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

Re: Canonical add-hook idiom


From: Stefan Monnier
Subject: Re: Canonical add-hook idiom
Date: Sun, 16 Nov 2003 23:26:29 GMT
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

> What is the preferred approach given these examples:
>     1). (add-hook 'some-mode-hook (lambda () [...]
>     2). (add-hook 'some-mode-hook '(lambda () [...]
>     3). (add-hook 'some-mode-hook (function (lambda () [...]
>     4). None of the above -- please explain.

The '(lambda form is to be avoided: the ' says "what follows
is pure data" whereas what follows is actually code, so it's
confusing (I expect humans won't get confused, but byte-compilers
do get confused).

`lambda' is a macro that expands to (function (lambda so the two are
pretty much interchangeable.  As for #'(lambda, it is a shorthand
for (function (lambda.

I thus recommend (lambda since it's the shortest and ask people to stay away
from '(lambda since it poses problems to the byte-compiler (as well as to
other code-walkers such as some fancy CL macros (typically
`lexical-let')).  But if you prefer #(lambda or (function (lambda,
that's OK: you won't burn in hell for it.


        Stefan


reply via email to

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