From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Canonical add-hook idiom Date: Sun, 16 Nov 2003 23:26:29 GMT Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1069025760 7498 80.91.224.253 (16 Nov 2003 23:36:00 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 16 Nov 2003 23:36:00 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Nov 17 00:35:58 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1ALWQw-00087j-00 for ; Mon, 17 Nov 2003 00:35:58 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1ALXNU-0003AL-Ra for geh-help-gnu-emacs@m.gmane.org; Sun, 16 Nov 2003 19:36:28 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!logbridge.uoregon.edu!snoopy.risq.qc.ca!charlie.risq.qc.ca!53ab2750!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 23 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 Original-NNTP-Posting-Host: 132.204.24.42 Original-X-Complaints-To: abuse@umontreal.ca Original-X-Trace: charlie.risq.qc.ca 1069025189 132.204.24.42 (Sun, 16 Nov 2003 18:26:29 EST) Original-NNTP-Posting-Date: Sun, 16 Nov 2003 18:26:29 EST Original-Xref: shelby.stanford.edu gnu.emacs.help:118353 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:14293 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:14293 > 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