Bitwise not (~) do noting on windows64



I tried bitwise not operator (~) and get the unchanged result

~123 #=> 123
while -124 is expected according to the document.
I uses v0.5.0 on windows64.

Could anyone tell me the proper way to use this operator ?

julia> Sys.KERNEL

julia> VERSION

julia> ~123

I’m getting the same result for 0.5.0 too, so maybe you rebound ~ to something else by accident? Can you reproduce this if you start a new REPL session?


There is no problem on a new REPL.
Checking the command history, I found this typo :

julia> ~=typeof(123)

Apparently this line caused my problem.

Thank you !


I’ve brought this up before, but I suppose it is worth repeating-- it is far too easy in Julia to accidentally redefine Base operators, and these redefinitions can have baffling and insidious effects. Could the language be revised slightly so that redefinition of an operator requires some more obvious block of code? For example, instead of + = 7, maybe

   Base.+ = 7

The core developers need to have pity on the future grad students who will be lab assistants in courses that will use Julia.


FWIW + = 7 does absolutely nothing with Base.


As @yuyichao mentioned, there is a difference between shadowing and overriding. You can’t accidentally override Base operators without being explicit somewhere.