From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: xah lee Newsgroups: gmane.emacs.devel Subject: Re: Idempotency of add-hook wrt lambda expressions Date: Wed, 4 Mar 2009 12:13:08 -0800 Message-ID: References: Reply-To: xah@xahlee.org NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=000325579e82207a6d046450aee0 X-Trace: ger.gmane.org 1236197610 13065 80.91.229.12 (4 Mar 2009 20:13:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 4 Mar 2009 20:13:30 +0000 (UTC) Cc: Geoff Gole , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Mar 04 21:14:42 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 1LexUI-0004Yc-8c for ged-emacs-devel@m.gmane.org; Wed, 04 Mar 2009 21:14:42 +0100 Original-Received: from localhost ([127.0.0.1]:56094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LexSw-0003YY-Px for ged-emacs-devel@m.gmane.org; Wed, 04 Mar 2009 15:13:18 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LexSs-0003YT-J0 for emacs-devel@gnu.org; Wed, 04 Mar 2009 15:13:14 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LexSr-0003YD-9S for emacs-devel@gnu.org; Wed, 04 Mar 2009 15:13:13 -0500 Original-Received: from [199.232.76.173] (port=58362 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LexSr-0003YA-4b for emacs-devel@gnu.org; Wed, 04 Mar 2009 15:13:13 -0500 Original-Received: from yx-out-1718.google.com ([74.125.44.158]:48040) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LexSq-0007az-Sj for emacs-devel@gnu.org; Wed, 04 Mar 2009 15:13:13 -0500 Original-Received: by yx-out-1718.google.com with SMTP id 34so2095037yxf.66 for ; Wed, 04 Mar 2009 12:13:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:reply-to:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=+6PNYv7QmO4iDlk14MHUokTB9i7P6v4meVvmmxV+lnM=; b=GrVpicgUwoVLLrQs7xztCIWovA5aUMqrIpBarmO4jCGsMPfBE65qd8gPKovcap5rtF wzuV191OiOa5zmr8rKEmsmVobuivsGI5v4qdzex7Dm66rYxXyECGjWOW7mq9/7skNkA/ mPEKbFd8cy7jkoQqrwPDHV9cl7Nwh9jZlD46w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; b=OeF4P61mXDXwAFkbOc68DzmnWRob9vvKlmb8tgSqwltNREXP5vogMYc+UJla9bepgF K1fTOY6/PtHEIXccFYRqxoPzVoa6Anbc7/5IK92xR+o71RnHKqL2kW3Wjih2z/Sm8AYo tqlfhsF6dR5E5jTdpYxNR/giDkqYGNe4ODsK4= Original-Received: by 10.231.30.198 with SMTP id v6mr93823ibc.26.1236197588367; Wed, 04 Mar 2009 12:13:08 -0800 (PST) In-Reply-To: X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) 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:109450 Archived-At: --000325579e82207a6d046450aee0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On Wed, Mar 4, 2009 at 6:18 AM, Stefan Monnier wrote: > > 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. > i prefer this be transparent to the user as Geoff Gole suggested. My reason is that from a user point of view, lambda serves the same purpose as function name, and one less thing to worry about problems that might come from byte compiling. if the code suggested does fix this without any other problems, why not? cheers, Xah --000325579e82207a6d046450aee0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Wed, Mar 4, 2009 at 6:18 AM, Stefan Monnier <= span dir=3D"ltr"><monnier@ir= o.umontreal.ca> wrote:
> Say a file contains an add-hook form with a lambda a= rgument:
> =C2=A0 (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). =C2=A0But occasionally a lambda is really exactly what you want, of course.
=
=
i=C2=A0prefer this be transparent to the user as Geoff Gole suggeste= d.

My reason is that from a user point of view, lambda ser= ves the same purpose as function name, and one less thing to worry about pr= oblems that might come from byte compiling.

if the= code suggested does fix this without any other problems, =C2=A0why not?

cheers,

=C2=A0=C2=A0Xah
--000325579e82207a6d046450aee0--