[#157] | project: specification | priority: medium | category: missing feature | |
---|---|---|---|---|
submitter | assigned to | status | date submitted | |
Burak | Martin | won't fix | 2003-09-30 10:52:33.0 | |
subject | assignments -= and += | |||
code |
//in java it is possible to write int i=0; i += 5; i++; // why not in Scala ? // +=, -=, ++, -- could apply to variables // e.g. python started supporting this after v2, // due to ever-repeating feature requests |
|||
what happened | ||||
what expected | ||||
[back to overview] |
Burak edited on 2003-09-30 10:53:02.0 |
Matthias edited on 2003-09-30 23:41:16.0 |
I don't see how you could smoothly add support for +=, -=, etc. to Scala. In Scala, these are methods of a value/object and not a variable. |
Burak edited on 2003-10-01 11:16:43.0 |
One way would be to consider it just as syntactic sugar
i += Eis trnasformed to i = i + Eby the parser, if i has no + method or types clash, tant pis. |
Matthias edited on 2003-10-03 12:03:49.0 |
Syntactic sugar is no option since += is a legal operator that can freely be used by the programmer. Do you want to restrict the operator syntax? For what operators do you support the syntactic sugar? For +, -, *, /? Why not also for |, &, ||, &&, %, ^, !, ?, etc? Also, no one says that + is a binary operator. This is up to the programmer to define. The benefit you get with your proposal is little and the restrictions you have to make are big. So I don't think it makes sense to support the Java/C-style assignment operators for primitive types. |
Burak edited on 2003-10-03 14:26:07.0 |
but isn't the lhs of an assignment a reference cell ?
if it is, then we can predefine += and -= for ints, strings or wherever + is defined. increment and decrement is a more frequent operation (in imperative, Java-like style) than |, & and what not, which would justify a special treatment. Why not make a general convention that transforms operator x op= y to x = x op y for binary operators, at least for primitive types. I don't think it is good programming style do define operators that include the = symbol which do not have this meaning. it is like using + for multiplication. I would argue that every C,C++,Java programmer has the same intuition of op= operators (and probably Ruby and Python programmers as well). in C++, the copy constructor &= is also a form of assignment.. |
Martin edited on 2003-10-09 12:31:06.0 |
Without overwhelming pressure from the Scala community at large I think this is too much complication for too little gain. Maybe in v2. Let's wait and see what Scala users say. |