Earlier quoted context omitted.
Yes, Julia really lets one get wild with Unicode. There are certain classes of unicode characters that we have marked as invalid for identifiers, some which are used for infix operators, and some which count as modifiers on previously typed characters which is useful for creating new infix operators, e.g. one might define julia> +²(x, y) = x^2 + y^2 +² (generic function with 1 method) such that julia> -2 +² 3 13 If s…
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 : ∞, ±, ≠…
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/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)