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: Trouble with lexical-binding. Date: Wed, 15 Apr 2015 10:44:04 -0400 Message-ID: References: <20150413220317.GC6324@acm.fritz.box> <87h9shec3s.fsf@yahoo.fr> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1429109135 25683 80.91.229.3 (15 Apr 2015 14:45:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 15 Apr 2015 14:45:35 +0000 (UTC) Cc: Alan Mackenzie , emacs-devel@gnu.org To: Nicolas Richard Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 15 16:45:21 2015 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 1YiOYF-00082x-HV for ged-emacs-devel@m.gmane.org; Wed, 15 Apr 2015 16:44:27 +0200 Original-Received: from localhost ([::1]:60806 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YiOYE-00015B-Kw for ged-emacs-devel@m.gmane.org; Wed, 15 Apr 2015 10:44:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34510) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YiOY0-000156-Nd for emacs-devel@gnu.org; Wed, 15 Apr 2015 10:44:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YiOXy-0005dn-29 for emacs-devel@gnu.org; Wed, 15 Apr 2015 10:44:12 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:50703) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YiOXx-0005dj-Sy for emacs-devel@gnu.org; Wed, 15 Apr 2015 10:44:09 -0400 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id t3FEi58S009227; Wed, 15 Apr 2015 10:44:05 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id D355315D9; Wed, 15 Apr 2015 10:44:04 -0400 (EDT) In-Reply-To: <87h9shec3s.fsf@yahoo.fr> (Nicolas Richard's message of "Wed, 15 Apr 2015 15:48:39 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.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 RV5277=0 X-NAI-Spam-Version: 2.3.0.9393 : core <5277> : inlines <2717> : streams <1422919> : uri <1907370> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.20 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:185456 Archived-At: > I don't think it can break code defined elsewhere : the (defvar ptr) > form only has effect in its lexical scope, unlike the 2+ arguments > versions where a default value is provided. Indeed, these (defvar ) are sufficiently common that I had to make sure that they don't wreak havoc too often, so such `defvar' try their best to only affect the current scope (typically: the current file). But if you have a file foo.el with ;;; - lexical-binding:t -*- (defun foo (x) (let ((ptr x)) (lambda (y) (+ ptr y)))) and a file bar.el with ;;; - lexical-binding:t -*- (defvar ptr) (defun bar () (let* ((ptr 6) (f (foo 3))) (message "%S" (funcall f 1)))) Then emacs -Q --batch -l ~/tmp/foo.elc -l ~/tmp/bar.el --eval '(bar)' and emacs -Q --batch -l ~/tmp/foo.el -l ~/tmp/bar.el --eval '(bar)' won't give you the same answer :-( Stefan