Notice how since numbers are immutable, Julia uses the bit level
representation to test identity, but for mutable types it uses memory
adresses.
And for strings, but string are immutable in Julia right? Because otherwise
the help from "help(is)" is confusing me.
Compares mutable objects by address in memory, and
compares immutable objects (such as numbers) by contents at the bit level.
Julia strings are immutable, so the help description is misleading:
julia> "test"[1] = "T"
ERROR: no method setindex!(ASCIIString, ASCIIString, Int32)
Ruby does have them mutable:
irb(main):002:0> a = "test"
=> "test"
irb(main):003:0> a[0] = "T"
=> "T"
irb(main):004:0> a
=> "Test"
Just as you expected it to be with the numbers:
julia> d = Dict{String, String}()
Dict{String,String}()
julia> x = "test"
"test"
julia> y = convert(UTF8String, x)
"test"
julia> typeof(x), typeof(y)
(ASCIIString,UTF8String)
julia> x == y
true
julia> x === y
false
julia> d[x] = "...mmmh!"
"...mmmh!"
julia> d[x]
"...mmmh!"
julia> d[y]
"...mmmh!"
julia> # Memory adresses:
julia> pointer_from_objref(x), pointer_from_objref(y)
(Ptr{Void} @0x09d4e2d0,Ptr{Void} @0x09e1f9b0)