unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: Canonical add-hook idiom
Date: Sun, 16 Nov 2003 23:26:29 GMT	[thread overview]
Message-ID: <jwvoevbucje.fsf-monnier+gnu.emacs.help@vor.iro.umontreal.ca> (raw)
In-Reply-To: GWitb.1387$n56.744@newsread1.news.pas.earthlink.net

> 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

      parent reply	other threads:[~2003-11-16 23:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-15  5:35 Canonical add-hook idiom Bob Nelson
2003-11-15  8:25 ` Oliver Scholz
2003-11-15 18:27   ` Henrik Enberg
2003-11-15 16:55 ` Jesper Harder
2003-11-16 23:26 ` Stefan Monnier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvoevbucje.fsf-monnier+gnu.emacs.help@vor.iro.umontreal.ca \
    --to=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).