From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kelly Dean Newsgroups: gmane.emacs.help Subject: Unreferenced symbols in closures, and a problem with closures in minor modes Date: Tue, 28 May 2013 15:35:58 -0700 (PDT) Message-ID: <1369780558.54419.YahooMailClassic@web141103.mail.bf1.yahoo.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1369780588 32016 80.91.229.3 (28 May 2013 22:36:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 28 May 2013 22:36:28 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed May 29 00:36:27 2013 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 1UhSVF-0007CX-NO for geh-help-gnu-emacs@m.gmane.org; Wed, 29 May 2013 00:36:25 +0200 Original-Received: from localhost ([::1]:48150 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhSVF-0001G6-Bs for geh-help-gnu-emacs@m.gmane.org; Tue, 28 May 2013 18:36:25 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:38407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhSUv-0001F1-Pk for help-gnu-emacs@gnu.org; Tue, 28 May 2013 18:36:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UhSUp-0006bD-JC for help-gnu-emacs@gnu.org; Tue, 28 May 2013 18:36:05 -0400 Original-Received: from nm49.bullet.mail.bf1.yahoo.com ([216.109.114.65]:25217) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhSUp-0006b6-4w for help-gnu-emacs@gnu.org; Tue, 28 May 2013 18:35:59 -0400 Original-Received: from [98.139.212.151] by nm49.bullet.mail.bf1.yahoo.com with NNFMP; 28 May 2013 22:35:58 -0000 Original-Received: from [98.139.212.225] by tm8.bullet.mail.bf1.yahoo.com with NNFMP; 28 May 2013 22:35:58 -0000 Original-Received: from [127.0.0.1] by omp1034.mail.bf1.yahoo.com with NNFMP; 28 May 2013 22:35:58 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 502067.22660.bm@omp1034.mail.bf1.yahoo.com Original-Received: (qmail 55431 invoked by uid 60001); 28 May 2013 22:35:58 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1369780558; bh=iEfzmnOwSHX8epq8pBzM0qtv6cWuCyUcKWRtlI7P3sU=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Subject:To:MIME-Version:Content-Type; b=sCBw8KtrO7GF8YKVwFCQ2Nt7qBbuzN9CnSsy6Zu2Msjdp9j9w19yEFvoF1cj351SL+rZs0noRswR0c40wDdIXzz6tEiHspX+xyCGYfyaoRAT3oPhTjBRgT7gnN63B5QylVOsTZNjrePFsTxOJ7PMfoCyMdkLVElSXECHBSX0vlY= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Subject:To:MIME-Version:Content-Type; b=aBjbMGIl/kmAeqANIJ8p9bYgdPuNajTgwUyqtb+wAvG/jltuSX7avS/Z/euvJdPPUI+9i9kJ957jXrkrLQO3e/ZCkRZEi2x9EU6W26bQLfLkOAXHIF0X3ilenUVr4o3ve5VjZ/yVQTeRbvsammNE0J/5aePSrnL86s7Z7eeRE4k=; X-YMail-OSG: 1nuRMKkVM1n0fN9iYn_XHrzvS1JIo3X4.NSmdsZ8u2sCCPf 5WoCrK50zpOdRXLIhQDG_LTkV6AtELVPZbtbEkmyNG0AbcksLxBWLzNuoE6O xkNcU9NIzwFRcvCnxNDWXH04M7aTOrlUy10Oxto17IdsboluaGndQAf.RYx3 ccTwmVaIoXZncEaKXQmxKAC4UtjxSsp5u9G9bIs4eBs1kHhaiDXs_GzDy.NY GpO2jSEe9820DPhahFc9V4hbzcWQTZEwrmMjeyWgcLGoL6O6tU6M6t.Kuo8V z95CdzzOZGCl.ckSKIzsjQplyflaIjLnJrk3MWXDk2xmfTim79RqQlEsV44y jhqSBU1QTeBZ2YJxspzvsJRxko8MEIWJWrbZ4czN1NwqqLJkXBr9UV5JfOfF 4DG7QQN4lcynC2C0G47xZuaw45Taepke.Rg._ZuWTUTWHPF0l4jt8hE4i84v JwlIfYZXm22uJKhTUAkZ7N9KmCP5dICVGfkp3yktx9so- Original-Received: from [91.213.8.236] by web141103.mail.bf1.yahoo.com via HTTP; Tue, 28 May 2013 15:35:58 PDT X-Rocket-MIMEInfo: 002.001, KHNldHEgbGV4aWNhbC1iaW5kaW5nIHQpCgpBcyBleHBlY3RlZCwgKGxldCAoKHggMCkpIChsYW1iZGEgKCkgeCkpIC0.IChjbG9zdXJlICgoeCAuIDApIHQpIG5pbCB4KQpCdXQsIChsZXQgKCh4IDApKSAobGFtYmRhICgpIDApKSAtPiAoY2xvc3VyZSAoKHggLiAwKSB0KSBuaWwgMCkKQW5kLCAobGFtYmRhICh4KSB4KSAtPiAoY2xvc3VyZSAodCkgKHgpIHgpCgpXaHkgZG8gY2xvc3VyZXMnIGxleGljYWwgZW52aXJvbm1lbnRzIGluY2x1ZGUgdW5yZWZlcmVuY2VkIHN5bWJvbHM_IEFuZCB3aHkgcHJvZHVjZSABMAEBAQE- X-Mailer: YahooMailClassic/15.1.8 YahooMailWebService/0.8.144.546 X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 216.109.114.65 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:91113 Archived-At: (setq lexical-binding t) As expected, (let ((x 0)) (lambda () x)) -> (closure ((x . 0) t) nil x) But, (let ((x 0)) (lambda () 0)) -> (closure ((x . 0) t) nil 0) And, (lambda (x) x) -> (closure (t) (x) x) Why do closures' lexical environments include unreferenced symbols? And why produce a closure with an empty environment, instead of just a lambda form? And I have a problem with unwanted closures in minor modes: (defvar foo-hook nil) (define-minor-mode bar "Bar" nil " Bar" nil (if bar (add-hook 'foo-hook (lambda () (bar 0)) nil t) (remove-hook 'foo-hook (lambda () (bar 0)) t))) M-x bar RET C-h v foo-hook RET, and I get: foo-hook's value is ((closure ((last-message) (arg . toggle) t) nil (bar 0)) t) Which won't be removed when foo-hook runs, because arg will be 0, not 'toggle. I tried to thwart the closure like this: (defvar foo2-hook nil) (define-minor-mode bar2 "Bar2" nil " Bar2" nil (if bar2 (add-hook 'foo2-hook (let ((arg 0)) (lambda () (bar2 0))) nil t) (remove-hook 'foo2-hook (let ((arg 0)) (lambda () (bar2 0))) t))) M-x bar2 RET C-h v foo2-hook RET, and I get: foo2-hook's value is ((closure ((arg . 0) (last-message) (arg . toggle) t) nil (bar2 0)) t) Argh! Surely this is a misfeature? Also I don't know why last-message is there, but at least it doesn't interfere. On a previous experiment that I can't reproduce, involving several additions and removals, I got: Value: ((closure ((last-message) (arg . 1) i t) nil (bar 0)) (closure ((last-message) (arg . 1) i t) nil (bar 0)) t) I have no idea what the symbol i means or where it came from. If it were setting i to nil in the lexical environment, it would be (i), not i. Also, the two closures are identical, yet add-hook isn't supposed to add duplicates. Help?