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: Pascal J. Bourguignon
Subject: Re: Real-life examples of lexical binding in Emacs Lisp
Date: Sat, 30 May 2015 14:59:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

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

-- 
__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


reply via email to

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