Posts Tagged “rust”
Proper Notation for Scalar Multiplication in Rust:2019-04-17
Dispatching on the Right-Hand Side of Operators and Rusts's Orphan Rule
The scalar multiplication in a vector space is written kv in math, where k is a scalar value (e.g. a number) and v is a vector. It would be nice to write
k * vin programming languages, to stay close to the familiar notation. Object-oriented languages typically only support calling methods on the first argument. But the scalar normally doesn't know about vectors, so it can't easily do that.
Python works around this with theMore ...
__rmul__special method for defining the
__rmul__is called on the right-hand side object with the left-hand side as the argument, the reverse of what
__mul__does. This works well, but feels a bit like a hack.