3 ms·
Maybe an operator-overloading region? #{ m3 = m1 * m2 + m3; m3 += m4; } Basically, pure syntactic sugar to help the author express inten
by thechao 3y ago
Maybe an operator-overloading region?
#{
m3 = m1 * m2 + m3;
m3 += m4;
}
Basically, pure syntactic sugar to help the author express intent without having to add a bunch of line-chatter.
Speaking of operator-overloading, I really wish C++ (anyone!) had a `.` prefix for operator-overloading which basically says "this is more arguments for the highest-precedence operator in the current expression:
a := b * c .+ d;
Which translates to:
a := fma(b, c, d)
- MH15 3y agoHuh I've never seen this approach. Very interesting solution, could be adapted to the JavaScript matrix libraries I bet.
- thechao 3y agoThis is how TeX handles math — the "$" operator is an "inline" version of the same.
- estebank 3y agoIn Rust you could use a proc macro that parsed the block and translates the token to a new token stream that uses method calls with the appropriate operator precedence, for arbitrary operations you could want to define. You're effectively writing a compiler plugin and language extension at that point. For targeted niche domains, this might be worthwhile.
- bakkoting 3y agoThere's a not-very-active proposal to add operator overloading to JS which takes a similar scoped approach: https://github.com/tc39/proposal-operator-overloading https://github.com/tc39/proposal-operator-overloading