3 ms·
Nice ! Python allows to define operators too, but AFAIK you can't use Unicode in those ? And ² (or any other sub/superscript number - at least some letters are
by BlueTemplar 6y ago
Nice ! Python allows to define operators too, but AFAIK you can't use Unicode in those ? And ² (or any other sub/superscript number - at least some letters are fine) is not allowed in identifiers either.
The point is to get closer to math notation though, if anything x +² y is IMHO even farther away than (x + y)*2 !
Any way to have (x + y)² or √(x + y) to work ?
––––
The new AZERTY has a lot of improvements : ∞, ±, ≠, √, the whole Greek alphabet, () and [] and {} next to each other... but for some reason they've removed the ² that the old AZERTY had ?
http://norme-azerty.fr/ http://norme-azerty.fr/
- eigenspace 6y ago> if anything x +² y is IMHO even farther away than (x + y) * 2 ! Yeah, it was just a random example that came to mind, not to be taken seriously. Here's perhaps one example of unicode being used in a way that's pleasing to some and upsetting to others: https://www.reddit.com/r/programminghorror/comments/jqdi4i/yes_this_is_unicode/ https://www.reddit.com/r/programminghorror/comments/jqdi4i/y... > Any way to have (x + y)² or √(x + y) to work ? The sqrt one works out of the box actually, no new definitions required: julia> √(1 + 3) 2.0 The second one does not work because we specifically ban identifiers from starting with superscript or subscript numbers. If it was allowed, we could work some black magic with juxtaposition to make it work. Here's an example with the transpose of an array: julia> struct ᵀ end julia> Base.:(*)(x, ::Type{ᵀ}) = transpose(x) julia> [1, 2, 3, 4]ᵀ 1×4 transpose(::Vector{Int64}) with eltype Int64: 1 2 3 4 Basically, we have a system called 'juxtaposition' where 2x is parsed as 2*x (but not x2). It generalizes in funky ways one can abuse if they really want (kinda discouraged though)