From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: Real-life examples of lexical binding in Emacs Lisp Date: Wed, 17 Jun 2015 02:43:45 +0200 Organization: Informatimago Message-ID: <87616ntb9a.fsf@kuiper.lan.informatimago.com> References: <87bnh3eqiv.fsf@mbork.pl> <874mmuxyd5.fsf@gnu.org> <87k2v6wmpy.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1434501923 7256 80.91.229.3 (17 Jun 2015 00:45:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Jun 2015 00:45:23 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jun 17 02:45:19 2015 Return-path: Envelope-to: geh-help-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 1Z51Th-0002EZ-O0 for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Jun 2015 02:45:17 +0200 Original-Received: from localhost ([::1]:43484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z51Th-0003ka-2v for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Jun 2015 20:45:17 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 83 Original-X-Trace: individual.net TeWxvdiUd4kJeceYs+8YmQcLqrs1ngLuV5cJ1LUguWx8Wi0Xi9 Cancel-Lock: sha1:NGYzZDI5ZjMxYmI5MGFlZDc2NjQyZTgxODI5MzU0M2E3YWE3Y2VlNw== sha1:hgciRjSSgfRuWDR9LJtoSCNWDRs= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:212710 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:104994 Archived-At: Jim Diamond writes: > On 2015-06-14 at 08:31 ADT, Pascal J. Bourguignon wrote: >> Marcin Borkowski writes: >> >>> Exactly. What I'm curious is how lexical scoping might make some tasks >>> *connected to editing* easier/more natural. > > > >> Writing programs is easier and more natural with lexical scoping, IN >> GENERAL! > > > > Really? Are there well-agreed-upon studies showing those things? > Or are they your opinion? Yes, there are well-agreed-upon studies showing this. This is the reason ALL programming languages created since 1970, use lexical binding exclusively. > It strikes me that lexical scoping is easier to implement for compiled > languages (that is an "off the cuff" comment from someone (me) with > basic knowledge of compiler construction). But if lexical scoping is > "more natural", is that because more people were "brought up" with > lexically-scoped languages than dynamically-scoped languages? No, this is for theorical reasons, and in practice, because lexical scoping allows to understand the semantics of programs by just looking at the source, without executing it, and therefore make it easier on the programmers, and ease debugging and maintainance. > A few versions of emacs ago something I was using went from dynamic > scoping to lexical scoping. Working around that change was not > trivial, casting suspicion on the universality of "easier". The not trivial comes from the fact that it was wanted to perform the transition without rewriting all the existing elisp code, not only in the GNU emacs distribution, but also all the unpublished elisp code on the disks of all the users. Therefore, in emacs: 1- dynamic binding is still the default, 2- lexical binding is optional (you have to mark a file specially to get it). There may also be some technicalities with respect to the buffer-local variables which is an emacs specific complexity; I've not looked into it yet. Also, I would say that in emacs, given the number of hooks there are, lexical binding should demonstrate definite and overwhelming advantages over dynamic binding, since there is no closure with dynamic binding. For example, compare: (setq lexical-binding nil) (let ((message (read-from-minibuffer "Message: "))) (push (lambda () (insert message)) text-mode-hook)) [enter some text, type RET, then switch to *scratch* and:] M-x text-mode RET (pop text-mode-hook) with: (setq lexical-binding t) (let ((message (read-from-minibuffer "Message: "))) (push (lambda () (insert message)) text-mode-hook)) [enter some text, type RET, then switch to *scratch* and:] M-x text-mode RET (pop text-mode-hook) -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk