[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: My wish list :) [RE: How can we make lua better?]
- From: RLake@...
- Date: Wed, 5 Jun 2002 14:37:19 -0500
>> 2) += and -= operators
>Vote: NO
> I vote yes. This is actually a huge thorn, IMO, and makes scripts much
> more verbose than they need to be:
> Table1.table2.table3.table4.value += 1
> OR:
> Table1.table2.table3.table4.value =
> Table1.table2.table3.table4.value + 1
> OR:
> local tempTable = Table1.table2.table3.table4
> tempTable.value = tempTable.value + 1
> I choose the first one. Additionally, the first one allows the Lua VM
> to make certain optimizations that make it WAY faster than #2 and even
> faster than #3.
The problem with the "certain optimizations" is that they may not be
correct in the face of tag methods.
Unless a "getset" tagmethod is implemented, it is hard to see how to know
when the optimization
could be made. (And then we'd need "indexset", too, I suppose.)
Nonetheless, with carefully defined semantics, I think this could be a
valuable addition; it would be really nice for cases like:
a[expensive_computation(i)] += 1
(which should be syntactic sugar for:
do local _index = expensive_computation(i)
a[_index] = a[_index] + 1
end
without any other attempt to optimize).
A generalisation to multiple assignment sort of suggests itself.
For another justification of idioms like this, there is a nice paper on
Todd Proebstring's pages which mentions the high cost (to the programmer)
of thinking up names of unnecessary variables.