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 defined by the caller not the called? Date: Sat, 04 May 2013 16:01:27 -0400 Message-ID: References: <87a9oisxp5.fsf@ferrier.me.uk> <87txmq27nc.fsf@kuiper.lan.informatimago.com> <8738uasqlk.fsf@ferrier.me.uk> <87ppxe21al.fsf@kuiper.lan.informatimago.com> <87vc76r1d0.fsf@ferrier.me.uk> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1367697703 3170 80.91.229.3 (4 May 2013 20:01:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 4 May 2013 20:01:43 +0000 (UTC) Cc: "Pascal J. Bourguignon" , emacs-devel@gnu.org To: Nic Ferrier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 04 22:01:41 2013 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 1UYieL-0006H6-AF for ged-emacs-devel@m.gmane.org; Sat, 04 May 2013 22:01:41 +0200 Original-Received: from localhost ([::1]:43281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYieK-0007rZ-S2 for ged-emacs-devel@m.gmane.org; Sat, 04 May 2013 16:01:40 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53390) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYieF-0007nc-AG for emacs-devel@gnu.org; Sat, 04 May 2013 16:01:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UYieE-00009g-Eg for emacs-devel@gnu.org; Sat, 04 May 2013 16:01:35 -0400 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:48688) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYieE-00009S-B6 for emacs-devel@gnu.org; Sat, 04 May 2013 16:01:34 -0400 Original-Received: from fmsmemgm.homelinux.net (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id r44K1SHh023163; Sat, 4 May 2013 16:01:29 -0400 Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id DACA1AE1B2; Sat, 4 May 2013 16:01:27 -0400 (EDT) In-Reply-To: <87vc76r1d0.fsf@ferrier.me.uk> (Nic Ferrier's message of "Sun, 28 Apr 2013 18:50:19 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV4569=0 X-NAI-Spam-Version: 2.3.0.9362 : core <4569> : streams <954042> : uri <1411561> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.22 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:159297 Archived-At: >>> How do I check for lexical-binding then? >> Read again the code I posted along. > I did. I can't see how that shows me how to test lexical-binding though. > It seems like I can't tell if I'm executing in a lexical-binding > environment or not. > I want to be able to write a macro that understands when it is, or is > not, executing code inside a lexical-binding environment. It's a good question. But you need to be careful about what you mean because the code you showed does not do what you describe (e.g. it doesn't do any macro expansion). Testing the value of `lexical-binding' from within a function won't tell you if that function is itself using lexical binding or not. But testing `lexical-binding' during macro expansion should tell you whether the expanded code will be interpreted as lexically scoped or not. It's actually not 100% reliable (e.g. lexical-binding is a buffer-local variable, so if you switch buffer during your macro expansion, you might bump into some corner cases), but it should work well in practice (tho less so in 24.1 where there were a few more problematic cases that I had forgotten). Stefan