From unknown Sun Jun 22 22:44:43 2025 X-Loop: help-debbugs@gnu.org Subject: bug#14772: 24.3; defvar and lexical-binding in interpreted elisp code Resent-From: Jisang Yoo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 02 Jul 2013 21:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 14772 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 14772@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.137279931324048 (code B ref -1); Tue, 02 Jul 2013 21:09:02 +0000 Received: (at submit) by debbugs.gnu.org; 2 Jul 2013 21:08:33 +0000 Received: from localhost ([127.0.0.1]:52974 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Uu7oO-0006Fn-4i for submit@debbugs.gnu.org; Tue, 02 Jul 2013 17:08:32 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44321) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Uu7Yo-0005po-Sc for submit@debbugs.gnu.org; Tue, 02 Jul 2013 16:52:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uu7Ye-00079h-Lr for submit@debbugs.gnu.org; Tue, 02 Jul 2013 16:52:21 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:39708) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uu7Ye-00079U-IG for submit@debbugs.gnu.org; Tue, 02 Jul 2013 16:52:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uu7YZ-00035b-Jk for bug-gnu-emacs@gnu.org; Tue, 02 Jul 2013 16:52:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uu7YR-0006x0-7y for bug-gnu-emacs@gnu.org; Tue, 02 Jul 2013 16:52:11 -0400 Received: from mail-qa0-x22b.google.com ([2607:f8b0:400d:c00::22b]:43402) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uu7YR-0006wt-4I for bug-gnu-emacs@gnu.org; Tue, 02 Jul 2013 16:52:03 -0400 Received: by mail-qa0-f43.google.com with SMTP id d13so3162091qak.16 for ; Tue, 02 Jul 2013 13:52:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; bh=HOU+xRmMy/0vZ48m1sM9iO3WiaOXbu0OhO8yAIU7a1E=; b=i5P3pMNTb8/8R3x2cDA1wfvmxf0evSy6Vw0RgSmCpcX67YCNEk53zdz8jhwucAWLI4 CTul/EtR5XJFn7ROIYfbaT/kTx1awErZPMbw5SEecuym4MC7mo+ILMagUNx9ybTw555g WngcKvO8V2Yk79DGtNJqGYexCLTijeTZ5Lc8jJV6BfhJknGs0a4URBIWINCAjB9JsvlQ GB699YOU3DMSHjNf6dK1ANJUwpIwPx4YDu9HMjWM5I/lYpm15r7ER9gf/HaaxJ9E2K9Z WbWNySpMJJbtnjZqZ8B6b1uZBx3yObntbZR64ai7TxbZDRXwyOHYe8r9lFNygBAHF6IL MORA== MIME-Version: 1.0 X-Received: by 10.49.35.180 with SMTP id i20mr40722677qej.61.1372798322562; Tue, 02 Jul 2013 13:52:02 -0700 (PDT) Received: by 10.224.121.4 with HTTP; Tue, 2 Jul 2013 13:52:02 -0700 (PDT) Date: Wed, 3 Jul 2013 05:52:02 +0900 X-Google-Sender-Auth: I0PYtDedAG-RJ_oQatJZNBfBYrQ Message-ID: From: Jisang Yoo Content-Type: text/plain; charset=ISO-8859-1 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.3 (----) X-Mailman-Approved-At: Tue, 02 Jul 2013 17:08:30 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.3 (----) Short description: Declaring a special variable affects lexical local variables of the same name (in interpreted code) in a half measure way, thereby deviating from both the newbies expectation and the common lisp expectation. Long description: contents of alice.el: ;; -*- lexical-binding: t; -*- ;; 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)))) ;; breaking bad (defvar foo 1000) ;; time to see its effects (print (list :R3 (mapcar (alice-multiplier-1 10) (list 1 2 3)) :R4 (mapcar (alice-multiplier-2 10) (list 1 2 3)))) Output from emacs -q --load alice.el: (:R3 (10 20 30) :R4 (1000 2000 3000)) What I expected: Either (:R3 (10 20 30) :R4 (10 20 30)) or (:R3 (1000 2000 3000) :R4 (1000 2000 3000)) One answer in http://stackoverflow.com/questions/17400556/strange-interaction-between-lexical-binding-and-defvar-in-emacs-lisp 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. From unknown Sun Jun 22 22:44:43 2025 X-Loop: help-debbugs@gnu.org Subject: bug#14772: 24.3; defvar and lexical-binding in interpreted elisp code 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: To: Jisang Yoo Cc: 14772@debbugs.gnu.org Received: via spool by 14772-submit@debbugs.gnu.org id=B14772.13728438142852 (code B ref 14772); Wed, 03 Jul 2013 09:31:02 +0000 Received: (at 14772) by debbugs.gnu.org; 3 Jul 2013 09:30:14 +0000 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 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 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 Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id 8D4FAAE15B; Wed, 3 Jul 2013 05:30:02 -0400 (EDT) From: Stefan Monnier Message-ID: References: Date: Wed, 03 Jul 2013 05:30:02 -0400 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) MIME-Version: 1.0 Content-Type: text/plain 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-Spam-Score: -1.3 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) 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 From debbugs-submit-bounces@debbugs.gnu.org Sun Jul 28 14:25:49 2019 Received: (at control) by debbugs.gnu.org; 28 Jul 2019 18:25:49 +0000 Received: from localhost ([127.0.0.1]:47141 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hrnrg-0000y3-RW for submit@debbugs.gnu.org; Sun, 28 Jul 2019 14:25:49 -0400 Received: from quimby.gnus.org ([80.91.231.51]:59726) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hrnrf-0000xw-3h for control@debbugs.gnu.org; Sun, 28 Jul 2019 14:25:47 -0400 Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=marnie) by quimby.gnus.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hrnrc-0006cf-Gm for control@debbugs.gnu.org; Sun, 28 Jul 2019 20:25:46 +0200 Date: Sun, 28 Jul 2019 20:25:44 +0200 Message-Id: <87o91e9ftj.fsf@mouse.gnus.org> To: control@debbugs.gnu.org From: Lars Ingebrigtsen Subject: control message for bug #14772 X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: close 14772 quit Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) close 14772 quit