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: lexical-binding questions Date: Tue, 15 May 2012 16:14:49 -0400 Message-ID: References: <871umzrvfw.fsf@gmail.com> <33827449.post@talk.nabble.com> <87vcjylmfl.fsf@gnu.org> <33849639.post@talk.nabble.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; CHARSET=US-ASCII Content-Transfer-Encoding: 7BIT X-Trace: dough.gmane.org 1337112903 19754 80.91.229.3 (15 May 2012 20:15:03 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 15 May 2012 20:15:03 +0000 (UTC) Cc: Emacs-devel@gnu.org To: egnarts-ms Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue May 15 22:15:00 2012 Return-path: Envelope-to: ged-emacs-devel@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 1SUO95-0003HR-Fd for ged-emacs-devel@m.gmane.org; Tue, 15 May 2012 22:14:59 +0200 Original-Received: from localhost ([::1]:41228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUO94-00057j-R4 for ged-emacs-devel@m.gmane.org; Tue, 15 May 2012 16:14:58 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUO91-00056K-VX for Emacs-devel@gnu.org; Tue, 15 May 2012 16:14:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SUO8z-0007KH-A5 for Emacs-devel@gnu.org; Tue, 15 May 2012 16:14:55 -0400 Original-Received: from relais.videotron.ca ([24.201.245.36]:21040) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SUO8z-0007JW-5m for Emacs-devel@gnu.org; Tue, 15 May 2012 16:14:53 -0400 Original-Received: from fmsmemgm.homelinux.net ([24.201.208.110]) by VL-VM-MR003.ip.videotron.ca (Oracle Communications Messaging Exchange Server 7u4-22.01 64bit (built Apr 21 2011)) with ESMTP id <0M42000HEYWRCTB0@VL-VM-MR003.ip.videotron.ca> for Emacs-devel@gnu.org; Tue, 15 May 2012 16:14:51 -0400 (EDT) Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id 2E8AFAE0E5; Tue, 15 May 2012 16:14:49 -0400 (EDT) In-reply-to: <33849639.post@talk.nabble.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-Received-From: 24.201.245.36 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:150506 Archived-At: >> Also, it reminded my of this: >> (setq lexical-binding t) >> (let ((t 0)) t) => error >> (let ((nil 0)) nil) => 0 Funnily enough, the byte-compiler behaves pretty much the same, and yet the underlying reasons are completely different. Basically: nil and t are not marked as special-variable-p, so they are considered candidates for lexical scoping; but t is used as the last element of the interpreter's lexical environment (basically because a nil lexical environment is used to mean "lexical-binding = nil"), so it behaves as if there'd been a (defvar t) earlier, which in turns explains why the error is signalled since we then try to set the global variable `t' which is immutable. For nil, this doesn't show up, so it's treated as a lexically scoped var. for the compiler case, byte-compile-not-lexical-var-p actually special-cases t and nil so they're treated as dynamically bound, but in your nil case above, we never even attempt to bind nil because the "let body is nil" triggers an optimization (which (c|sh)ould also apply to the "let body is t" case, but that's not implemented). Anyway, I guess nil and t should be marked as special-variable-p, if for no other reason than because they are pretty damn special. Stefan