lua-users home
lua-l archive

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


Edgar Toernig <froese@gmx.de> writes:

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

Are you asking if a language can have both lexically scoped and
dynamically scoped variables at the same time?  Yes, this is true, but
a language that allows some dynamic variables is not considered to be
static or lexically scoped.

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

The rule I sited about nested functions is a consequence of the usual
definition of lexical scoping.  Here is the definition I found at
http://lua.swiki.net/13 on July 27th:

   In a lexically scoped language, the scope of an identifier is fixed
   at compile-time to be the smallest block (begin/end or
   function/procedure body) containing the identifier's
   declaration. This means that an identifier declared in some block
   is only accessible within that block and from procedures declared
   within it.

That link is no longer accessible from that page, but if you know it,
I would greatly appreciate it if you would send it to me.

As I scan some of the links I have found, I notice that when they
equate lexical scoping with static scoping, they also define lexical
scoping as above.  I can only conclude that if you believe there is
no difference between lexical and static scoping, than you must
conclude that Lua is not statically scoped.

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

This is correct.  The situation is more interesting.  If you prohibit
all local variables including function parameters, than Lua would also
be lexically scoped.  The lack of nested scoping in the presence of
nested functions is why Lua is not lexically scoped.

On another subject, can we agree that Lua variables do not have nested
scope? 

John