lua-users home
lua-l archive

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


"John D. Ramsdell" wrote:
> 
> > You mix scope with accessibility.
> 
> The purpose of scoping rules is to define accessibility.

No.  Possible accessibility or better visibility.  Access rules
are a completely different thing.  I.e. take a pseudo language
that has attributes for input and output parameters (input are
read only, output are write only):

  define foo(in: a,b; out: x)
    x:=a+b  -- ok
    a:=1    -- error: trying to change read-only var a
    z:=x    -- error: trying to read write-only var x
  end

Scope rules define which a, b, and x are taken (the formal parameters
of foo).  Access rules define what you may do with them.  Or take an
attribute 'private' that prohibits access from nested functions i.e.
to better document usage or avoid closure generation:

  define foo()
    private x
    define bar()
      print x  -- error: unable to access private x
  ...

The same here.  The scope rules define what declaration is chosen and
access rules what you are allowed to do with them.

Access rules may even be dynamic (especially in dynamically typed lang-
uages like Lua).  I.e. you may set the setglobal/getglobal tag methods
to restrict access to global variables.  Or you may create references
to variables and suddenly they become accessible from anywhere, ignoring
any scoping rules.

> Look at the FOLDOC definition of lexical scoping.
> 
>      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.
> 
> It defines lexical scoping by describing when and were a variable is
> accessible.  Accessibility is what scoping is all about.

Again.  The FOLDOC entry is not a formal definition.  And I read the
last sentence as: An identifier declared in some block is never visible
outside of that block - only within it.  [Note: access may even be possible
from outside of that block via references.]  Btw, this definition is so
short-sighted that even C++ would not conform.


To your other posting:
>
> Let me make it clear that any definition of lexical scoping taken from
> a Scheme source will further my case.  In the eighties, general
> agreement was found.  The Scheme reference on
>
>   http://lua-users.org/wiki/LuaScopingDiscussion
>
> is
>
>   http://www.htdp.org/2001-01-18/Book/node104.htm
>
> a classic example of a link that furthers my cause.

This is a "How is lexical scoping done in some kind of Scheme".  Try to
get away from that specific rule set.  Take a more general view of scoping
and you may have much less problems with different styles ;-)


We should take this discussion off the mailing list.  Nobody else seems
to be interested in it any more.  If you want to continue this discussion
(which I find very interesting) then I think it would be better to reply
by private mail.

Ciao, ET.