mita icon indicating copy to clipboard operation
mita copied to clipboard

Strings can be concatenated using += but not by using infix addition

Open sawtschuk-appropos opened this issue 6 years ago • 2 comments

In Mita, the following code is legal:

var str1 = 'Hello ';
var str1 += 'World';

but the following code is not legal;

var str1 = 'Hello ';
var str1 = str1 + 'World';

Semantically speaking, += is an arithmetic operator, and naturally expected to be a shorthand for an infix addition between two operators. Hence, the second code fragment would be expected to be legal.

I am not sure if this is a bug or intended. If it is intended, I would deem this a usability issue, since code such as the code fragment below, which is not yet possible in Mita, would be natural to write in most modern languages that also feature the += operator for strings.

var firstName = 'Alexander';
var lastName = 'Sawtschuk';
var fullName = firstName + ' ' + lastName;

sawtschuk-appropos avatar May 29 '18 15:05 sawtschuk-appropos

this should be fixed in #320

csweichel avatar Mar 26 '19 07:03 csweichel

this should be fixed in #320

Sadly no, especially since general concatenation of buffers is more complicated than appending, for example if source and destination are the same buffer.

In general this could be solved by transforming a = b + c;, with no constraints on identity of a, b and c, to this:

var b_copy = b;
b_copy += c;
a = b_copy;

wegendt-bosch avatar Mar 28 '19 08:03 wegendt-bosch