From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#14772: 24.3; defvar and lexical-binding in interpreted elisp code Date: Wed, 03 Jul 2013 05:30:02 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1372843873 13254 80.91.229.3 (3 Jul 2013 09:31:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 3 Jul 2013 09:31:13 +0000 (UTC) Cc: 14772@debbugs.gnu.org To: Jisang Yoo Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 03 11:31:13 2013 Return-path: Envelope-to: geb-bug-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 1UuJP6-00063I-Os for geb-bug-gnu-emacs@m.gmane.org; Wed, 03 Jul 2013 11:31:12 +0200 Original-Received: from localhost ([::1]:52597 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UuJP6-0002dW-CX for geb-bug-gnu-emacs@m.gmane.org; Wed, 03 Jul 2013 05:31:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UuJP2-0002dH-9q for bug-gnu-emacs@gnu.org; Wed, 03 Jul 2013 05:31:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UuJOw-0000fO-T2 for bug-gnu-emacs@gnu.org; Wed, 03 Jul 2013 05:31:08 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:59423) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UuJOw-0000ec-MK for bug-gnu-emacs@gnu.org; Wed, 03 Jul 2013 05:31:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1UuJOw-0000lI-9Z for bug-gnu-emacs@gnu.org; Wed, 03 Jul 2013 05:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 03 Jul 2013 09:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 14772 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 14772-submit@debbugs.gnu.org id=B14772.13728438142852 (code B ref 14772); Wed, 03 Jul 2013 09:31:02 +0000 Original-Received: (at 14772) by debbugs.gnu.org; 3 Jul 2013 09:30:14 +0000 Original-Received: from localhost ([127.0.0.1]:53737 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UuJO6-0000jo-Nt for submit@debbugs.gnu.org; Wed, 03 Jul 2013 05:30:11 -0400 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:46477) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1UuJO1-0000j8-Go; Wed, 03 Jul 2013 05:30:06 -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 r639U20l002842; Wed, 3 Jul 2013 05:30:03 -0400 Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id 8D4FAAE15B; Wed, 3 Jul 2013 05:30:02 -0400 (EDT) In-Reply-To: (Jisang Yoo's message of "Wed, 3 Jul 2013 05:52:02 +0900") 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 RV4627=0 X-NAI-Spam-Version: 2.3.0.9362 : core <4627> : streams <993295> : uri <1465585> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:75841 Archived-At: tags 14772 wontfix thanks > ;; two functions that are supposed to do the same thing > (defun alice-multiplier-1 (foo) > (lambda (n) (* n foo))) > (defun alice-multiplier-2 (num) > (let ((foo num)) > (lambda (n) (* n foo)))) They're not supposed to be equivalent, because function arguments in lexical-binding mode are documented as always being lexical, regardless of any defvar. > Output from emacs -q --load alice.el: > (:R3 (10 20 30) :R4 (1000 2000 3000)) That's arguably a bug in the interpreter, indeed. The byte-compiler returns (:R3 (10 20 30) :R4 (10 20 30)) AFAIK. The byte-compiler should also point out the fact that there's a problem in the code: we let-bind `foo' first and later on declare foo with defvar. > suggests that (:R3 (1000 2000 3000) :R4 (1000 2000 3000)) should be > the right output, which is the same as the CLIST output according to > my test. All three answers can be considered correct depending on what semantics we want to give to the language (I happen to prefer the semantics we currently get from the compiler). The fact that we get different results with the interpreter and with the compiler is a bug, but making the interpreter follow the compiler's behavior would be difficult/costly and making the compiler follow the interpreter's behavior is also difficult/costly. So I prefer to say that such code is "unsupported": you should always place the defvar before let-binding the corresponding variable. Stefan