4 ms·
Would you be able to do nice looking syntax like this in Nim? x² x÷y
by eviks 3y ago
Would you be able to do nice looking syntax like this in Nim?
x²
x÷y
- V1ndaar 3y agoYeah, unicode characters in Nim code are supported. However, if by `x²` you'd want to square an identifier `x`, that won't work. The Nim lexer parses `x²` as a single identifier. We do have infix unicode operators though. So `x ÷ y` (spacing required though!) could be implemented easily. I use this for `±` in Measuremancer [0] (which btw also supports Unchained units, for error propagation on unitful measurements). [0]: https://github.com/SciNim/Measuremancer https://github.com/SciNim/Measuremancer
- eviks 3y agoRequired spacing is a blocker/friction, that's one of the benefits of DSLs, I guess, being able to eschew the conservative syntax of the general-purpose languages (though Unicode support is a good step forward)