lua-users home
lua-l archive

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


"John D. Ramsdell" wrote:
> 
> Edgar Toernig <froese@gmx.de> writes:
> 
> > I think the confusion is on your side because you make a distinction
> > between lexical and static scoping.  It's the same.  If you think
> > I'm wrong give a reference to a text that defines the difference.
> 
> I got to run, and am taking some time off, but I'll get back to you on
> this.  I believe the pointer on lua-user.org fully explains the
> concept of lexical scoping.  It's not the opposite of dynamic scoping,
> did you notice?

Well, lexical and dynamic scope are the two basic scoping rules.
Not opposing rules but two sets that can exist together.

To the lua-user.org pointer.  You wrote:

   "In a static language, all variable references can be resolved at
   compile time. In a lexically scoped language, nested functions have
   access to variables defined in their enclosing functions."

A lot of formal text books I read does not even mention functions when
defining lexical/static and dynamic scoping.  They use the term "scope"
or "block".  The most formal ones even omit the "most closely nested"
rule when defining lexical scoping and only say that this is an often
found addition.  And I've yet to see a book that makes a difference
between lexical and static scope.

> C is a boring example of a lexically scoped language because it meets 
> the nested function test by prohibiting them.
>[...]
> The point to focus on is that if a language fails the nested function
> test, it's not lexically scoped.  There is no need to consider other
> issues.

I think that this a pretty personal and unique requirement.  It would
mean that if I prohibit nested function definitions in Lua[1] it would
become "lexically" scoped without changing any scoping rules![2]

Ciao, ET.

[1] Just insert this line at lparser.c:body:1095:
  check_condition(ls, ls->fs->prev == NULL, "function nesting prohibited");

[2] Sounds like "If a car has a stereo it must have min 2x50W else it's
    no longer a car." ;-)