swift-numerics icon indicating copy to clipboard operation
swift-numerics copied to clipboard

Unicode operators

Open Roman-Kerimov opened this issue 4 years ago • 5 comments

Since Swift supports Unicode in identifiers, it is possible to improve the appearance of the code by adding aliases for operators, such as: × ⋅ ÷ ∶ (RATIO) - (MINUS SIGN), etc.

What do you think of it?

Roman-Kerimov avatar Nov 08 '19 21:11 Roman-Kerimov

I think it would be perfectly fine for a developer who prefers this spelling to create a third-party library to vend these operators. However, Swift has standardized on a certain spelling for operators. This issue has already been discussed on Swift Evolution in the past and I don't see how the design of existing standard library operations would fall into the scope of Swift Numerics.

xwu avatar Nov 09 '19 02:11 xwu

Basically what Xiaodi said.

The one place where I might consider a novel operator in the medium-term future would be around matrix multiplication (where we have a very real need to have a symbol for both the composition of linear maps--normal matrix multiply--and the Hadamard--or elementwise--product). Even there, though, the most obvious and precedented solution is * and .*, so I'm relatively unlikely to look to unicode unless there's a truly great option.

stephentyrone avatar Nov 09 '19 17:11 stephentyrone

I'm marking this wontfix for the medium term. It's something we might consider in the far-off future.

stephentyrone avatar Nov 11 '19 14:11 stephentyrone

I agree that we should stick to ASCII operators for the foreseeable future. However, just as a point of reference, I have been using a number of operators in my personal code, to write things like this:

let a = √2
let b = 1/√2
let c = -√2
let d = √-c
let e = 2√3
let f = (1+√5)/2

…and I also have:

typealias ℂ = Complex<Double>

NevinBR avatar Nov 20 '19 23:11 NevinBR

I would be open to a "cute operators" module at some future point; they really do make reading some code much nicer.

stephentyrone avatar Nov 21 '19 00:11 stephentyrone