[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: augmented operators (was: implicit parameters)
- From: Edgar Toernig <froese@...>
- Date: Sat, 10 Feb 2001 03:37:49 +0100
Nick Trout wrote:
> Have you though about adding augmented operators eg. +=, -= etc in Sol?
I guess every C programmers comes to the point to think about
this ;-) But I came to the same conclusion as the Lua team:
I do not plan to add them to Sol. IMHO it's not worth the
The only good thing an them is that it's a little bit shorter
to write. On some occasions it may even be much shorter. But
besides that it gives nearly nothing except a more complicated
system. And some constructs would be just weird and give no
_obvious_ results (ie "a,b += c" is what?).
One may think that it could be faster to execute. But it isn't
if you want the semantic of "a += b" is "a = a + b" (with "a"
evaluated only once). There are two types of storage in Lua/Sol:
tables and locals. For tables you have to perform the two
accesses to the table (read and write) because of possible tag-
methods (get/settable). Nothing to optimize here. Locals could
be optimized with a special instruction but again you have to
consider tag methods for "+" and that reduces the possible
optimization to <numlocvar>+=<num> .
One could try to make += and co special operators (ie "incr_by",
"mul_by", ...) with appropriate tag methods. But that requires
references to objects and these only exist for tables, not for
locals. (Btw, the same problem exists for "++" and "--".)
Beside that it would make the language more complicated.
Result: you would only get some very expensive syntactic sugar ;)
 This case could be optimized even without the special
syntax. But I think it won't be noticeable in any reasonable
application so I'm not trying to do this at the moment. But
if somebody has a nice patch for this ...