In C #, there is no built-in concept of commutativity in a language. That is, if I define a simple Vector class, for example:
public struct Vector { private readonly double x, y, z; ... public static Vector operator +(Vector v, double d) {...} }
I still need to define the symmetric operator +(double d, Vector v) , or any expression of the form 2.1 * v will give a compilation error or fail at run time in a dynamic script.
My question is twofold: firstly, are there any languages where you can define commutative operators without having to define as possible combinations of operands? In other words, are there languages familiar with the concept of switching? And secondly, it’s ever been reviewed in C # and revised, since it’s really just syntactic sugar, to avoid a few extra keystrokes that really don’t add all that richness to the language (and most likely, an additional reserved word)?
c # programming-languages
Inbetween
source share