Bitwise not (~) do noting on windows64

question

#1

Hi.
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 ?


#2
julia> Sys.KERNEL
:NT

julia> VERSION
v"0.5.1"

julia> ~123
-124

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?


#3

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 !


#4

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.


#5

FWIW + = 7 does absolutely nothing with Base.


#6

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