lua-users home
lua-l archive

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


From: Roberto Ierusalimschy
> If you have no globals to reference would you do:
>     global      -- turns on dmode (only inside f)
>>There is a small syntactical problem here.
  global
  a, b, c = 1, 2, 3
>>is not "global a,b,c". One solution is to add a specific "mark" for such
cases ("global ;", "global -", anything like this). Another is simply
to agree that when you write "global _" you do not want to really
use global "_"  ;-)

From: John Belmonte
>>The other problem with this is that it's quite strange for the word
"global"
by itself to mean "don't use globals by default".

Good points. It would read better if you had a "use" keyword? Dont like the
idea of "dummy" variables eg. "global _"
eg.
function x()
use global c
local a=5   -- fine
b=6    -- oops
c=99    -- fine
end

or:
function y()
  use global
  a = 5   -- oops
end

Then you might add a scope? :-) ie. optional "global" and "do...end" )

global tab = { d=8 }

function x(t)
 use global c,tab do
  local a=5   -- fine
  b=6    -- oops
  c=99    -- fine
  a=d  -- fine (from t)
 end
c=99    -- oops
end

x(tab)

I appreciate adding this "use x do ... end" might cause just as many
problems as this scoping discussion is trying to solve.

N