Why is there the difference between !=
and !==
operators?
Examples:
julia> a = Any["D", "A", "s", "t"]
julia> filter(e->e!="s",a)
3-element Array{Any,1}:
"D"
"A"
"t"
julia> filter(e->e !== "s",a)
4-element Array{Any,1}:
"D"
"A"
"s"
"t"
Why is there the difference between !=
and !==
operators?
Examples:
julia> a = Any["D", "A", "s", "t"]
julia> filter(e->e!="s",a)
3-element Array{Any,1}:
"D"
"A"
"t"
julia> filter(e->e !== "s",a)
4-element Array{Any,1}:
"D"
"A"
"s"
"t"
see the docs for ===
!==
is the negation of ===
and !=
the negation of ==
What version of Julia are you using ?
in julia 1.6:
julia> a = Any["D", "A", "s", "t"]
4-element Vector{Any}:
"D"
"A"
"s"
"t"
julia> filter(e->e != "s",a)
3-element Vector{Any}:
"D"
"A"
"t"
julia> filter(e->e !== "s",a)
3-element Vector{Any}:
"D"
"A"
"t"
Cheers!
LTS, of course
(I’m smiling, because a while ago, I was told here, that it’s better not to stick to LTS)
This is for sure a weird bug
julia> versioninfo()
Julia Version 1.0.5
Commit 3af96bcefc (2019-09-09 19:06 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
julia> a = ["D", "A", "s", "t"];
julia> filter(e->e !== "s", a)
3-element Array{String,1}:
"D"
"A"
"t"
julia> filter(e->e !== "s", Any[a;])
4-element Array{Any,1}:
"D"
"A"
"s"
"t"
the compiler (?) probably thinks that since they are not the same type, they can’t be ===
I get the same results as you do. The example above was taken from SO post related to filter
.
Julia Version 1.0.5
Commit 3af96bcefc (2019-09-09 19:06 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
But in my code I had a string array, so it should have been working. But I didn’t use a string constant, but a string parsed from the symbol.
julia> a = ["D", "A", "s", "t"];
julia> ss = :s;
julia> filter(e->e !== string(ss),a)
4-element Array{String,1}:
"D"
"A"
"s"
"t"
julia> filter(e->e != string(ss),a)
3-element Array{String,1}:
"D"
"A"
"t"