From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nicolas Richard Newsgroups: gmane.emacs.help Subject: Re: Timer variable binding Date: Tue, 7 Jan 2014 21:57:31 +0000 (GMT) Message-ID: <1389131851.70949.YahooMailNeo@web172805.mail.ir2.yahoo.com> References: <87d2k3ydij.fsf@yahoo.fr> Reply-To: Nicolas Richard NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1389131888 18559 80.91.229.3 (7 Jan 2014 21:58:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 7 Jan 2014 21:58:08 +0000 (UTC) Cc: "help-gnu-emacs@gnu.org" To: Johan Andersson Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 07 22:58:15 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1W0ef1-0005S2-Ep for geh-help-gnu-emacs@m.gmane.org; Tue, 07 Jan 2014 22:58:07 +0100 Original-Received: from localhost ([::1]:43579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0ef1-0005Q7-4C for geh-help-gnu-emacs@m.gmane.org; Tue, 07 Jan 2014 16:58:07 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36774) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0eea-0005JL-6C for help-gnu-emacs@gnu.org; Tue, 07 Jan 2014 16:57:47 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W0eeT-0004bu-74 for help-gnu-emacs@gnu.org; Tue, 07 Jan 2014 16:57:40 -0500 Original-Received: from nm9.bullet.mail.ir2.yahoo.com ([212.82.96.71]:25552) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0eeS-0004bp-Sa for help-gnu-emacs@gnu.org; Tue, 07 Jan 2014 16:57:33 -0500 Original-Received: from [212.82.98.50] by nm9.bullet.mail.ir2.yahoo.com with NNFMP; 07 Jan 2014 21:57:31 -0000 Original-Received: from [212.82.108.250] by tm3.bullet.mail.ir2.yahoo.com with NNFMP; 07 Jan 2014 21:57:31 -0000 Original-Received: from [127.0.0.1] by omp1015.mail.ird.yahoo.com with NNFMP; 07 Jan 2014 21:57:31 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 699158.91758.bm@omp1015.mail.ird.yahoo.com Original-Received: (qmail 34937 invoked by uid 60001); 7 Jan 2014 21:57:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.fr; s=s1024; t=1389131851; bh=833I3pLEd+ZB16g4P+CE6cJqdILSWXXvp/K/u9fYIWc=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=yQT52pwmcf9YJEneQDrtH9As+uN/b7DTj6fKcpLJGdscQ46wcPUeyYsnO3O1HajWIWwiabG1xvJN1KMZFNxE9HFkiZHd59VYnJXfEJ0bXG3IqdpL/BKPq1DEGi53IYWXClW60Dxe4PpzeSIZrA3H2FuIgwD2zkoHYt/hNWqwtc0= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.fr; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=3OFGuwZTRr0mCAQ4OBnB8RXmGYZJvTraVsW65rqhF/taxAEnRLr+WN2hhOaLl1B6jy3oPW5+snSix/yGlwU3alF9I9tBtqsFpR/eKlzsLt1AWdU4LOKBEsGcxzd7WUqRSpFFHOrvsGIH5NshhSwGRF9c4cVU+HeWMpEVhfA6dHY=; X-YMail-OSG: 3w8OagoVM1k_YveKMRhLnWthv4ZGUbZkASjx.iZAdyCN8cs fvsDOMSKHBT0KeRU.KmbFe3jk_duUjV5wbPZm5zcbf7mrp0w5CQjX5fRE5vx xC7yNQ2Uf97utAev7sNkXMQBdf7_Xs68Q56zBic1pGL5_UZDDatKCuR70h9F vefv9UOpeBeSQcZ0xNeIMfep_h61iQE14E8QvArVc.O2VTwT3REZhndAGe9h 71os5IYHc5z9mvPLCnFLL0k4XHQA2eDHhXFZcw..CltbNulfSqyNFBV1UFfz sEbIXMT60G2r7RFILxSf330zribds88_wOw9RFyYSEOww6VzifD0ZDInWJnp FzDyV4yh78LLWXRecBfRZ7xr.y6YQNaBVAy293qoDItPCDT7AueJ0jFMoguX MPcL5hsl56OWfKxaq4f.6O0sJP0OanXJc.SPYOTfirAhuEVEqGKE20fMDvZB FcNBJKHOvhdKH6FtqsDnWeXhBRybMpM8PyFLObmRVHUh6OiOffbi8Ww0X96M XfEOkFQaqttFkJl6kxGnfbXaJ243R.PM7qn7sdsdALtSV82kHwf2TFfIgTeG A2GfbX_0- Original-Received: from [81.246.140.119] by web172805.mail.ir2.yahoo.com via HTTP; Tue, 07 Jan 2014 21:57:31 GMT X-Rocket-MIMEInfo: 002.001, PiBsZXQgKG15LXZhcj0xMCkgLT4gcnVuLWF0LXRpbWUgLT4gKm1hZ2ljKiAtPiBjYWxsYmFjay1mdW5jdGlvbgo.IExvb2tzIHRvIG1lIGxpa2UgdGhpcyBzaG91bGQgd29yaz8gQnV0IHdoeSBkb2Vzbid0IGl0PyA7KQoKQnkgdGhlIHRpbWUgdGhlIGNhbGxiYWNrIGlzIGNhbGxlZCwgdGhlIGxldCBmb3JtIGlzIGxvbmcgZ29uZS4gVGhlIGNhbGxiYWNrLWZ1bmN0aW9uIGlzIHN0b3JlZCBpbiBzb21lIHBsYWNlIChuYW1lbHksIGluIGEgdGltZXIgc3RydWN0dXJlIGluIHRoZSBnbG9iYWwgdmFyaWFibGUgdGkBMAEBAQE- X-Mailer: YahooMailWebService/0.8.172.614 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 212.82.96.71 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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 Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:95301 Archived-At: > let (my-var=3D10) -> run-at-time -> *magic* -> callback-function=0A> Look= s to me like this should work? But why doesn't it? ;)=0A=0ABy the time the = callback is called, the let form is long gone. The callback-function is sto= red in some place (namely, in a timer structure in the global variable time= r-list) and then, after some time, another piece of emacs code calls that f= unction. At that moment, there's no more let binding.=0A=0AWhy it works wit= h lexical binding is because the lambda is made into a closure, which then = knows what the symbol my-var is.=0A=0AIn a buffer where lexical-binding is = t, you can try evalling=0A(setq foobar (let ((my-var 0)) (lambda () (incf m= y-var) (message "my-var: %s" my-var))))=0Athe answer will be:=0A(closure ((= my-var . 0) t) nil (setq my-var (1+ my-var)) (message "my-var: %s" my-var))= =0Aif you now call (funcall foobar), you'll get "my-var: 1"=0Aand now, eval= ling foobar gives:=0A(closure ((my-var . 1) t) nil (setq my-var (1+ my-var)= ) (message "my-var: %s" my-var))=0AThis is magic !=0A=0ADoing the same with= out lex-bind will give you a lambda, then an error, then the same lambda.= =0A=0A-- =0A=0ANico.=0A