lua-users home
lua-l archive

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


> global x	-- make a global x

You can't do this in my proposal, you can only say "outer x" to import x
from an outer scope.

> y=1
>
>   function foo()

The rule to apply below is that the first assignment to a variable in a
function declares it local, so the code

>     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?

becomes

> local     x=a		-- what is x, what is a ?

(hence a is nil in this example)

> local    y=a		-- what is y?
> local    a=a		-- what's this?
>     a=a		-- and now?

(no local here, because it's the second assignment to a)

> local    b=1		-- and this?
>     if ... then
>       b=1	-- new b or same as above?
>       b=b+1	-- and here?
>     end

These assignments to b have the normal effect, since only the first
assignment makes b local. It could be argued that it's confusing that
removing the assignment to b in the outer block would make b local to the
if.

>     for b=1,10 do ... end		-- new b or same as above?
>     for c=1,10 do			-- again, new c?

for has special rules; I don't propose to change these.

>       ...=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.

I think you've misunderstood my proposal. I hope this clears it up; it's
quite simple, really, in its effects as well as its definition.

-- 
http://sc3d.org/rrt/ | computation, n.  automated pedantry