From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: Real-life examples of lexical binding in Emacs Lisp Date: Sun, 14 Jun 2015 12:55:31 +0200 Message-ID: <87d20y5zks.fsf@mbork.pl> References: <87bnh3eqiv.fsf@mbork.pl> <87d21i6x15.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1434279364 14517 80.91.229.3 (14 Jun 2015 10:56:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 14 Jun 2015 10:56:04 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jun 14 12:55:56 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 1Z45Zy-0005Jh-T6 for geh-help-gnu-emacs@m.gmane.org; Sun, 14 Jun 2015 12:55:55 +0200 Original-Received: from localhost ([::1]:58231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z45Zy-0003Uq-7r for geh-help-gnu-emacs@m.gmane.org; Sun, 14 Jun 2015 06:55:54 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z45Zj-0003Uc-FU for help-gnu-emacs@gnu.org; Sun, 14 Jun 2015 06:55:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z45Zg-000345-3q for help-gnu-emacs@gnu.org; Sun, 14 Jun 2015 06:55:39 -0400 Original-Received: from mail.mojserwer.eu ([2a01:5e00:2:52::8]:54629) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z45Zf-000340-Sq for help-gnu-emacs@gnu.org; Sun, 14 Jun 2015 06:55:36 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id 370964F6080 for ; Sun, 14 Jun 2015 12:55:35 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LsQV-3Dhn9Dw for ; Sun, 14 Jun 2015 12:55:33 +0200 (CEST) Original-Received: from localhost (unknown [109.232.24.146]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 9C0164F607B for ; Sun, 14 Jun 2015 12:55:32 +0200 (CEST) In-reply-to: <87d21i6x15.fsf@kuiper.lan.informatimago.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:5e00:2:52::8 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:104919 Archived-At: On 2015-05-30, at 14:59, Pascal J. Bourguignon wrote: > Tassilo Horn writes: > >> The emacs paper has a section explaining why emacs used dynamic binding >> from the start: http://www.gnu.org/software/emacs/emacs-paper.html#SEC17 >> >> However, to me the two example use-cases only motivate why you want to >> be able to use dynamic scoping for special variables (defvar), not >> really for local variables (let) or function parameters, although the >> first Edit Picture example explicitly speaks of binding command >> arguments but I don't understand it. > > Indeed, in general, you want lexical binding for local variables. > > However, I would argue that for global variables, lexical binding would > be useful too, even by default. > > In Common Lisp, we can implement global lexical variables, using > eg. symbol macros, but in emacs lisp, we're missing operators for the > global lexical case: > > dynamic lexical > global defvar - > local let(1) let(2) > > (1) when lexical-binding is nil or the variable has been defvar'ed. > (2) when lexical-binding is t and the variable has not been defvar'ed. > > >> But there are good use-cases for dynamic variables also in "normal" >> programs. One example is to be able to bind some *error-handler* >> dynamically in order to customize how to cope with errors that happen >> far below the call stack. > > Definitely. > > https://groups.google.com/forum/#!original/comp.lang.lisp/oC5gDvn42pM/IudCXzCtxowJ I'm sorry to say that I didn't understand that post. (Though I admit that I didn't try /very/ hard. I'll try harder again later.) Thanks anyway, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University