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)
	while ((not found) and (i<getn(table)) do
		if (table[i] == element) then
	return found

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