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.
  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
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 _"
function x()
use global c
local a=5   -- fine
b=6    -- oops
c=99    -- fine

function y()
  use global
  a = 5   -- oops

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)
c=99    -- oops


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