lua-users home
lua-l archive

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


On Sun, 2008-08-10 at 13:00 +0100, Duncan Cross wrote:
[...]
> > if(0 == (foo = a+b))
> 
> I'm being picky rather than advocating this be considered, but
> wouldn't it be able to make a slight improvement if "foo" were a
> global variable, by eliminating a globals table lookup?

Ah, but that assumes that (a = b) returns b! Take the following:

local t = {}
setmetatable(_G, {
	__newindex = function(_, k, v)
		t[k] = v + 1
	end
})

print(thing = 9)

This could plausibly return any of 9, 10 or nil, depending on which set
of semantics you decide on --- which to me is a good reason not to
decide on any of them, and go for the simple but intuitive approach of
not having assingment be an operator.

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ 
│ "The sky was the perfect untroubled blue of a television screen,
│ tuned to a dead channel." --- Neil Gaiman, _Neverwhere_

Attachment: signature.asc
Description: This is a digitally signed message part