Julia has two types of equality comparison:
- If you want to verify that x and y are identical, in the sense that no program can tell them apart. Then the right choice is to use the
is(x,y) function, and the corresponding operator, this type of comparison is the === operator. The tricky part is that two mutable objects are equal if their memory addresses are identical, but when comparing two immutable objects, is returns true if the contents are the same at the bit level.
2 === 2 #=> true, because numbers are immutable
"Foo" === "Foo" #=> false
- Operator
== or its equivalent isequal(x,y) function, which is called general matching and returns true if, firstly, a suitable method for this type of argument exists, and secondly, this method returns true. so what if this method is not specified? then == call the === operator.
Now for the aforementioned case, you have an immutable type that does not have the == operator, so you really call the === operator, and it checks to see if the two objects in the contents are identical at the bit level, and they are not because they belong to different string objects and "Foo" !== "Foo"
EDIT:
as mentioned in @Andrew, refer to the Julia documentation, strings have immutable data types, so why "test"!=="true" #=> true ? If you look at the structure of the String data type, for example, xdump("test") #=> ASCIIString data: Array(UInt8,(4,)) UInt8[0x74,0x65,0x73,0x74] , you will find that the rows have composite data types with the important data field. Julia strings are basically a sequence of bytes that is stored in a data field of type String. and isimmutable("test".data) #=> false
Reza afzalan
source share