From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Idempotency of add-hook wrt lambda expressions Date: Wed, 04 Mar 2009 09:18:12 -0500 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1236176308 23615 80.91.229.12 (4 Mar 2009 14:18:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 4 Mar 2009 14:18:28 +0000 (UTC) Cc: emacs-devel@gnu.org To: Geoff Gole Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Mar 04 15:19:45 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Lerwm-0000l6-Bt for ged-emacs-devel@m.gmane.org; Wed, 04 Mar 2009 15:19:44 +0100 Original-Received: from localhost ([127.0.0.1]:48784 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LervR-0001Sg-1L for ged-emacs-devel@m.gmane.org; Wed, 04 Mar 2009 09:18:21 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LervM-0001Ry-8N for emacs-devel@gnu.org; Wed, 04 Mar 2009 09:18:16 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LervK-0001Rg-39 for emacs-devel@gnu.org; Wed, 04 Mar 2009 09:18:15 -0500 Original-Received: from [199.232.76.173] (port=51051 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LervJ-0001Rd-UD for emacs-devel@gnu.org; Wed, 04 Mar 2009 09:18:13 -0500 Original-Received: from ironport2-out.pppoe.ca ([206.248.154.182]:19647 helo=ironport2-out.teksavvy.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LervJ-0004Wr-N5 for emacs-devel@gnu.org; Wed, 04 Mar 2009 09:18:13 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsQEACscrknO+KX2/2dsb2JhbACBTtY8hAgGhAU X-IronPort-AV: E=Sophos;i="4.38,301,1233550800"; d="scan'208";a="34676487" Original-Received: from 206-248-165-246.dsl.teksavvy.com (HELO pastel.home) ([206.248.165.246]) by ironport2-out.teksavvy.com with ESMTP; 04 Mar 2009 09:18:13 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id CC10C4B454; Wed, 4 Mar 2009 09:18:12 -0500 (EST) In-Reply-To: (Geoff Gole's message of "Wed, 4 Mar 2009 21:10:45 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.91 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:109442 Archived-At: > 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. Stefan