lua-users home
lua-l archive

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


Reuben Thomas wrote:
>
> 2. Local by default seems unnatural only if there is to you some
>    obvious global scope. [...]

Aside from the fact that the compiler would have to know _all_
globals (which would require an include statement!), what about
these examples?

global x	-- make a global x
y=1

  function foo()
    x=a		-- what is x, what is a?
    y=a		-- what is y?
    a=a		-- what's this?
    a=a		-- and now?
    b=1		-- and this?
    if ... then
      b=1	-- new b or same as above?
      b=b+1	-- and here?
    end
    for b=1,10 do ... end		-- new b or same as above?
    for c=1,10 do			-- again, new c?
      ...=function() print(c) end	-- will all funcs get the same c?
      c=c				-- what gives this?
      ...=function() print(c) end	-- and now?
      d=c
      ...=function() print(d) end	-- and now?
    end
  end

You will get really strange results with block scope and other
strange results with a single function scope.

Ciao, ET.