From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?utf-8?Q?Johan_Bockg=C3=A5rd?= Newsgroups: gmane.emacs.devel Subject: Re: Evil defvars in org.el Date: Fri, 04 May 2012 22:53:12 +0200 Message-ID: <87wr4rk6rr.fsf@gnu.org> References: <87k411g8xa.fsf@gnu.org> <877gx1pv19.fsf@gnu.org> <87vckls01f.fsf@gnu.org> <77ehr96ty6.fsf@fencepost.gnu.org> <874ns4sidf.fsf@gnu.org> <0u1un0cu4b.fsf@fencepost.gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1336164805 30723 80.91.229.3 (4 May 2012 20:53:25 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 4 May 2012 20:53:25 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri May 04 22:53:22 2012 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 1SQPVC-00032m-5c for ged-emacs-devel@m.gmane.org; Fri, 04 May 2012 22:53:22 +0200 Original-Received: from localhost ([::1]:51297 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SQPVB-00034o-FT for ged-emacs-devel@m.gmane.org; Fri, 04 May 2012 16:53:21 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SQPV7-00034I-I7 for emacs-devel@gnu.org; Fri, 04 May 2012 16:53:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SQPV5-0003bi-UB for emacs-devel@gnu.org; Fri, 04 May 2012 16:53:17 -0400 Original-Received: from smtprelay-b21.telenor.se ([195.54.99.212]:36533) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SQPV5-0003bR-K6 for emacs-devel@gnu.org; Fri, 04 May 2012 16:53:15 -0400 Original-Received: from ipb3.telenor.se (ipb3.telenor.se [195.54.127.166]) by smtprelay-b21.telenor.se (Postfix) with ESMTP id 2CAB1E08D for ; Fri, 4 May 2012 22:53:14 +0200 (CEST) X-SMTPAUTH-B2: [bocjoh] X-SENDER-IP: [85.229.0.223] X-LISTENER: [smtp.bredband.net] X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvFaACJBpE9V5QDfPGdsb2JhbABFijCoOhkBAQEBNzSCCQEBBAFWMwshJQ8BBBgBDAotG4dtCbsxjWiDJQSpKg X-IronPort-AV: E=Sophos;i="4.75,533,1330902000"; d="scan'208";a="110387136" Original-Received: from c-df00e555.04-211-6c6b701.cust.bredbandsbolaget.se (HELO muon.localdomain) ([85.229.0.223]) by ipb3.telenor.se with ESMTP; 04 May 2012 22:53:13 +0200 Original-Received: by muon.localdomain (Postfix, from userid 1000) id 9C78B4844FD; Fri, 4 May 2012 22:53:12 +0200 (CEST) Mail-Copies-To: never In-Reply-To: (Stefan Monnier's message of "Fri, 04 May 2012 11:29:22 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.54.99.212 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:150258 Archived-At: Stefan Monnier writes: >> It seems to me that this is something where there really ought to be >> a general Emacs solution (dynamic-let or whatever). > > There is such a thing: (defvar ). It currently has a number of problems: - The scoping of defvar is unclear and changes when the code is compiled: (setq lexical-binding t) (defun a () (let ((f (lambda () x)) (g (lambda () (defvar x)))) (funcall g) (let ((x 0)) (funcall f)))) (defun b () (let (f g) (setq f (lambda () x) g (lambda () (defvar x))) (funcall g) (let ((x 0)) (funcall f)))) (defun c () (let ((f (lambda () x))) (catch nil (defvar x)) (let ((x 0)) (funcall f)))) (defun d () (let ((f (lambda () x))) (progn (defvar x) (let (x))) ; "dlet" (let ((x 0)) (funcall f)))) ;; Interpreted (a) => error: (void-variable x) (b) => 0 (c) => 0 (d) => 0 ;; Compiled (a) => error (b) => error (c) => error (d) => 0 etc. - Invalid byte code is generated when the same symbol is used as both a lexical and a dynamic variable: (setq lexical-binding t) (setq foo (byte-compile '(lambda () (let (x) (defvar x) (let (x) 0))))) (disassemble foo) byte code: doc: ... args: 0 0 constant nil 1 dup 2 varbind x <<<< No matching `unbind' 3 constant 0 4 return (funcall foo) => Fatal error (6)Aborted