I’m conflicted here. With the correct ASCII operator ^ this works, but Julia does provide Unicode options in many cases, and could also support ˆ “Modifier Letter Circumflex Accent” for this. I’m not sure what else it could mean usefully. Does anyone use it for anything else?
For me ^ is the most natural power operator and ** just bad, that other languages like Python have.
Note, ^ is xor in other some other languages (e.g. C and Python, so can be a pitfall porting code), while Julia has ⊻ operator for it written \xor tab, or as a function xor(a, b). All operators in Julia are ASCII by default (often Unicode also) in Julia except that one, there the ASCII version is a function only.
My main struggle is actually the MacBook keyboard where the ASCI tilde and ^ are hidden from simple key strokes.
My left pinky is just getting board while the others are starting emacs like yoga exercises without any emacs in sight.
If it’s not on the keyboard that seems like an argument for some workaround… If Julia does it allowing the other ˆ it makes for some slight visual distinction in code bases, why I’m conflicted. It’s most likely also a technical breaking change. Maybe there’s some editor support available that maps it to ^? You can’t be the first to run into this problem… Xor is a rarely used function, so ^ for it in Python and C isn’t a deal breaker, but ^ (for power) is very common so Julia must be easy. Possibly it could be a warning, and then only in the REPL.
By the way, it’s quite easy to add your own REPL shortcuts, if there’s a particular character you need to type which isn’t in the REPL’s built-in tab completion dictionary:
For example, to have \power expand to ^:
using REPL
REPL.REPLCompletions.latex_symbols["\\power"] = "\u005e"
Put it in your ~/.julia/config/startup.jl file to run it every time you start a REPL.
According to the images of current Mac laptops on Apple’s web site, these characters are where they always are on a US keyboard: at the upper left (with shift-`) for ~ and at shift-6 for ^:
Well, I in fact have a physical Swiss-German keyboard and was running the en-US international layout.
Little did I know the en-US layout would be what I wanted and my fingers are used to.
But that was a quick fix.
No it could not. ˆ (U+02C6) is a modifier letter in Unicode (category Lm), and all modifier letters are allowed as part of identifiers in Julia as long as they follow an ordinary letter. e.g. xˆ2 is a valid identifier:
julia> xˆ2 = 16
16
julia> √xˆ2
4.0
Changing Julia to parse ˆ as a binary operator would therefore be a breaking change, and is hence technically disallowed in Julia 1.x.
(This is a weird case, so it’s not clear if anyone is actually using U+02C6 for identifiers in real code, and maybe it could be argued as a “minor” change for Julia 1.x. On the other hand, the ordinary ^ is an ASCII character (U+005E), and it is reasonable to require that anyone programming in any modern programming language be capable of typing it.)
In fact, it doesn’t have to follow an ordinary letter:
julia> const ˆ2 = exp2
exp2 (generic function with 10 methods)
julia> ˆ2(16)
65536.0
This is also allowed in Python 3:
>>> xˆ2 = 16
>>> xˆ2
16
>>> from numpy import exp2 as ˆ2
>>> ˆ2(16)
65536.0
In fact, I suspect that most modern computer languages allow this. The reason is that the general Unicode recommendations on identifier characters (Unicode Annex #31) suggest allowing modifier letters to start identifiers (property ID_Start). They do include a caveat that languages “may” want to specially handle modifier letters that resemble punctuation or other special characters, but I don’t know whether any languages do this for U+02C6.