help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Real-life examples of lexical binding in Emacs Lisp


From: Marcin Borkowski
Subject: Re: Real-life examples of lexical binding in Emacs Lisp
Date: Sun, 14 Jun 2015 12:55:31 +0200

On 2015-05-30, at 14:59, Pascal J. Bourguignon <pjb@informatimago.com> wrote:

> Tassilo Horn <tsdh@gnu.org> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]