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

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

Re: DynamicBindingVsLexicalBinding


From: Phillip Lord
Subject: Re: DynamicBindingVsLexicalBinding
Date: Mon, 14 Oct 2013 17:05:45 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Drew Adams <drew.adams@oracle.com> writes:

>> > Yes.  Which is especially important for a heavily interactive and
>> > customizable program such as Emacs.  Emacs users extend and
>> > otherwise modify or adapt the source code, and they do so sometimes
>> > on the fly and interactively.
>> 
>> I don't think this is an advantage of dynamic binding; it's just an
>> advantage of having lots of configuration options.
>
> Which are dynamically bound variables.  Perhaps you are not as lexical
> as you think. ;-)
>
> Do you mean that you are OK with assigning values to such global,
> dynamically bound variables at startup time, and you are OK with a
> user changing their values interactively anytime (e.g. using Customize),
> but you are not OK with code let-binding global, dynamically bound
> variables?  Assignment is OK by you, but not let-binding?


Well, users don't change their values anytime. For a start, they can
only change them when the interpreter is not doing anything else. An,
they tend not to do this often.

As far as I can see, something like the dynamic behaviour of let is
always possible in a lexical binding environment -- you just push the
global value onto a stack, and pop it off again afterwards; what can be
done by the lisp interpreter can be done in lisp also.

Do I like changing values of variables underneath the nose of a
function; in general, no, because I think it is a little unpredictable.

> http://www.gnu.org/software/emacs/emacs-paper.html#SEC17  (Richard
> Stallman, 1981), including:
>
> "Formal Parameters Cannot Replace Dynamic Scope
>
>  Some language designers believe that dynamic binding should be avoided,
>  and explicit argument passing should be used instead. Imagine that
>  function A binds the variable FOO, and calls the function B, which
>  calls the function C, and C uses the value of FOO. Supposedly A should
>  pass the value as an argument to B, which should pass it as an argument
>  to C. 

I haven't heard RMS talk about this recently, but 30 years ago is a
long time. One simple, alternative, solution to the problem is to pass
around a single map between A, B and C. Not often done in elisp, but
very common in R for instance, where functions will pass graphics
contexts around until it gets to someone who cares. 

Phil



reply via email to

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