lua-users home
lua-l archive

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


> > Reubem Thomas wrote:

No such person! (I think...) Did you mean "Reuben Thomas"?

> > What I *do* find useful is dynamic scope, as in BBC BASIC,
> > so that you can define variables in one procedure, and have
> > them accessible in all callees.
>
>      - - - That's it what I find extrem usefull too. - - -
>
>               *define variables in one procedure,*
>            *and have them accessible in all callees.*

But there's another nicer solution to this: lexical scoping with nested
functions. This is sort of provided in Lua by upvalues, but because upvalues
are frozen they don't work properly. It'd be better if Lua had proper
closures; then upvalues needn't be frozen, and we could use the full power
of lexical scoping.

> > But big programs are much easier to debug if you do declare
> > globals where they are used...
>
> Ok and what's the solution to access:
>
>    the own local and the local from one of the parent functions
>
> if local-by-default?

In that case you have to use different names. Same problem as when you
declare a local with the same name as a global; you can't (in most
languages) access the global after that. Or declare a local in the top-most
block of a function, and then another local with the same name in an inner
block.

> > More concretely, any variable that
> > occurs anywhere on the left hand side of
> > ":=" anywhere in a function would be declared
> > local to the function (not just local to the block).
>
> Oh no! :-(
>
> Please keep Lua as simple at it is. This is complicated stuff.

I agree, making := declare a variable function-local rather than block-local
is awkward.

-- 
http://sc3d.org/rrt/ | Quidquid latine dictum sit, altum viditur (Anon)