Equality in Julia is tested using ==
x = 5
if x == 5
println("x is five!")
end
However, a mistake I make all the time, even several times a day, over a period of several years, is to use = instead of == :
x = 5
if x = 5 # error
println("x is five!")
end
Recent Example 1:
I was writing some Julia code in the past week, where I needed to test a variable against several possible values – six in all:
if member=="SB" ...etc
if member=="SL" ...etc
if member=="SU" ...etc
if member="SN" ... etc
if member="ST" ... etc
if member="AUTO" ... etc
Yes, in writing six lines of code, I made the mistake 3 times. Then I cut and pasted it into about 4 other places.
I know what you’re thinking: what about that syntax highlighting in VSCode?
My Brain: “Oh, what pretty colors”
Recent Example 2:
While I was thinking of this post, I updated some C++ code. I added an if-then using “=” instead of “==” – and this was underneath two existing if-then statements that had it correct.
After 20+ years of math education, “=” for equality is not only permanently hard-wired into my brain, the wires are constructed of tungsten, with a cover of pure neutroium, and further protected by a think layer of concrete.
I Don’t Think I’m Alone In This
I know that SAS JMP, if you execute a JSL script, if the parser finds a “=” used in an if-then statement, pops up a dialog box saying, “Is this really what you want?”
How Julia Can Help
One of the great features of Julia is unicode operators. We can use ≠ for not equals, ≤ for less than or equals, and ≥ for greater than or equals. We even have ≡ for equivalence. It really cleans up if-then statements and makes them clearer.
What I would ask for is a Unicode alias for ==
What Symbol Could It Be?
I present to you three possibilities:
U+0225F ≟ (question equals) \questeq
U+0229C ⊜ (circled equals) \circledequal
U+02A75 ⩵ (two consecutive equal signs) \Equal or \Equ
Shortcut to type it:
I don’t care which symbol is chosen ( anyone? anyone?), but I would like the shortcut to enter it to be easy to type. That generally means: short, lowercase, and easy keys to reach for touch typists.
Unfortunately, ≡ is already using \eq.
⩵ has a shortcut, \Equ
I would prefer one that is all lower case (say, re-asigning \ieq ). But I could live with \Equ. It’s not too bad to type.
I would use it every time. As long as my right pinky stays of the = key, I won’t make the mistake.
Pathetic Begging
Thank you for your consideration.