GNU bug report logs - #14772
24.3; defvar and lexical-binding in interpreted elisp code

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Jisang Yoo <jisang.yoo.ac+org@HIDDEN>; Keywords: wontfix; dated Tue, 2 Jul 2013 21:09:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Added tag(s) wontfix. Request was from Stefan Monnier <monnier@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 14772 <at> debbugs.gnu.org:


Received: (at 14772) by debbugs.gnu.org; 3 Jul 2013 09:30:14 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jul 03 05:30:14 2013
Received: from localhost ([127.0.0.1]:53737 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1UuJO6-0000jo-Nt
	for submit <at> 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 <monnier@HIDDEN>)
 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 <monnier@HIDDEN>
To: Jisang Yoo <jisang.yoo.ac+org@HIDDEN>
Subject: Re: bug#14772: 24.3;
 defvar and lexical-binding in interpreted elisp code
Message-ID: <jwv7gh8yp4h.fsf-monnier+emacs@HIDDEN>
References: <CADtzDwbakcv0ujbw2+wRsULAmRk1mnUBWMnt+Gn6Qb6hZGj6ww@HIDDEN>
Date: Wed, 03 Jul 2013 05:30:02 -0400
In-Reply-To: <CADtzDwbakcv0ujbw2+wRsULAmRk1mnUBWMnt+Gn6Qb6hZGj6ww@HIDDEN>
 (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-Debbugs-Envelope-To: 14772
Cc: 14772 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
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




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#14772; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 2 Jul 2013 21:08:33 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Jul 02 17:08:33 2013
Received: from localhost ([127.0.0.1]:52974 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1Uu7oO-0006Fn-4i
	for submit <at> 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 <jisang.yoo.ac@HIDDEN>) id 1Uu7Yo-0005po-Sc
 for submit <at> 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 <jisang.yoo.ac@HIDDEN>) id 1Uu7Ye-00079h-Lr
 for submit <at> 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 <jisang.yoo.ac@HIDDEN>) id 1Uu7Ye-00079U-IG
 for submit <at> 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 <jisang.yoo.ac@HIDDEN>) id 1Uu7YZ-00035b-Jk
 for bug-gnu-emacs@HIDDEN; Tue, 02 Jul 2013 16:52:16 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <jisang.yoo.ac@HIDDEN>) id 1Uu7YR-0006x0-7y
 for bug-gnu-emacs@HIDDEN; 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 <jisang.yoo.ac@HIDDEN>) id 1Uu7YR-0006wt-4I
 for bug-gnu-emacs@HIDDEN; Tue, 02 Jul 2013 16:52:03 -0400
Received: by mail-qa0-f43.google.com with SMTP id d13so3162091qak.16
 for <bug-gnu-emacs@HIDDEN>; 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: <CADtzDwbakcv0ujbw2+wRsULAmRk1mnUBWMnt+Gn6Qb6hZGj6ww@HIDDEN>
Subject: 24.3; defvar and lexical-binding in interpreted elisp code
From: Jisang Yoo <jisang.yoo.ac+org@HIDDEN>
To: bug-gnu-emacs@HIDDEN
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-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Tue, 02 Jul 2013 17:08:30 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
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.




Acknowledgement sent to Jisang Yoo <jisang.yoo.ac+org@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#14772; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 31 Oct 2014 17:00:04 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.