3 ms·
this is equally untrue true for strings, of course. “foo”+”bar” != “bar” + “foo” there are valid non-commutative additions.
by hprotagonist 8y ago
this is equally untrue true for strings, of course.
“foo”+”bar” != “bar” + “foo”
there are valid non-commutative additions.
- karmakaze 8y agoand is also a good reason to use a different operator for it too such as & or. and even space in some languages.
- hprotagonist 8y agoin the specific case of strings, my preferred way to spell that in python is f”{'foo'}{'bar'}”
- edflsafoiewq 8y agoAn interesting example is C's pointer-integer addition. p + n == n + p, true, but this is a purely syntactic fact. The actual semantic question of commutativity, whether switching the order of the arguments leaves the value unchanged, cannot even be asked of pointer-integer addition since the arguments, having differing types, cannot be switched.
- hcs 8y agoIndeed in C even array[index] is equivalent to index[array], just in case you want to be confusing.