lua-users home
lua-l archive

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


> function f()
> 	-- I would prefer x to be local in this case
>         -- because the use of "x :=" declares it local
>         -- for the whole function, but it would also
>         -- be safe to treat it as non-local until
> 	-- the first use of "x :="
> 	z := x
> 	x := 3
> 	return z
> end
> 
> Tom.

What would happen if we have a variable "found" that is global
and we call the routine below:

function find(element, table)
	i:=1
	while ((not found) and (i<getn(table)) do
		if (table[i] == element) then
			found:=i
		end
		i:=i+1
	end
	return found
end

Do you mean that "found" would only be treated as local if an element was
found ?
If so and the global "found" is non-nil, this algorithm will fail (will
always return the value of the global "found").
Or you are proposing that this function gets translated into the current lua
semantics (in a kind o preprocessing) to something like:

function find(element, table)
local found ...

(this way, "found" will always be initialized with the value 'nil') ?

[]'s
Luiz