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: Rusi
Subject: Re: Real-life examples of lexical binding in Emacs Lisp
Date: Sat, 30 May 2015 08:23:24 -0700 (PDT)
User-agent: G2/1.0

On Saturday, May 30, 2015 at 6:20:13 PM UTC+5:30, Pascal J. Bourguignon wrote:
> Rusi  writes:
> 
> > I'd say you are getting this from the wrong end.
> > Today (2015) dynamic scoping is considered a bug
> 
> "Bug" is too strong a word here.
> 
> 
> > In 1960 when Lisp was invented of course people did not realize this.
> > This is just a belated bug-fix
> 
> It is actually in 1960 (or a few years after) when LISP was invented,
> that people realized there was the so called "Funarg problem".  During
> the 60s this problem has been studied, several (faulty) solutions
> proposed, and eventually the notions of lexical binding vs. dynamic
> binding and environments were elaborated.

I dont understand why the funarg problem is at issue here.

If foo calls bar (not nested within foo)
And bar references x which it does not define
The natural expection is a 'Variable undefined' error.
However in a dynamic scoping discipline, you will get the error if
foo does NOT define x; else bar will get foo's private x.
I dont see how this can be regarded as not buggy -- no need to bring in
functional/higher-order aspects at all.

> 
> Other languages such as Fortran and Algol had already something like
> lexical binding, but it was actually as accidental as the dynamic
> binding of LISP, and of no consequence, since in those languages it was
> not possible to create closures anyways. 

There is somebody-or-other's law (sorry cant remember the reference) to the 
effect:
When a language is designed from ground up it usually gets scoping right.
When a language slowly evolves out of mere configuration into more and more
features into full Turing-completeness, it invariably gets scoping wrong.
Examples (in addition to Lisp): perl, python, lua and most famously javascript

I conclude:
a. Scoping is a much harder problem than appears at first blush
b. Compiled languages tend to get it more right than interpreted


reply via email to

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