Is their any clear documentation that outlines what == and === does?

I’ve searched the documentation but was unable to find it. I found this answer on SO, however does any documentation exist that explains it?

2 Likes

type ? followed by == or === :slight_smile:

help?> ===
search: === == !==

  ===(x,y) -> Bool
  ≡(x,y) -> Bool

  Determine whether x and y are identical, in the sense that no program could distinguish them. First the
  types of x and y are compared. If those are identical, mutable objects are compared by address in memory
  and immutable objects (such as numbers) are compared by contents at the bit level. This function is
  sometimes called "egal". It always returns a Bool value.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> a = [1, 2]; b = [1, 2];
  
  julia> a == b
  true
  
  julia> a === b
  false
  
  julia> a === a
  true


4 Likes

It would be good to add that answer I wrote to the manual in the appropriate place though. Would be great if someone wanted to figure out where that is an make a pull request.

4 Likes

Yet another issue is that searching for == or === in the docs retrieves nothing. There was a recent post somewhere where someone asked for a dictionary of the names of the operators. For example, I am not sure what I should search for if I was looking for those and the search for the symbol does not lead me the right doc page.

I guess the page is this one: https://docs.julialang.org/en/v1/manual/missing/#Equality-and-Comparison-Operators

(“egal” returns nothing, but “equal to” takes us there)

I managed to find Base.:== and Core.:=== in the docs, but it wasn’t straightforward. === in the search bar gave no results, and == didn’t give a link to the docs for ==. However, a couple of those results were Base.:!= and Base.:!==, whose docs linked to their opposites.
I had trouble finding things in the docs with the search bar before, but I didn’t expect it for the == and === operators, just seems like if the REPL’s help?> can do it, so should the search bar.

2 Likes

It’s on my agenda — I think it would be best to make a section about === in the mathematical operations and elementary chapter since == and isequal are already there and after all === is one of the most elementary operations, and then

  1. contrast === with == and isequal,
  2. incorporate some conceptual explanation about equality from Kent Pitman’s famous post on Lisp,
  3. explain what’s going on with mutable struct and struct, including corner cases,
  4. relate to hashing,
  5. suggest that if the user is unsatisfied with the existing comparison semantics, they should feel free to go ahead and define their own, with the tons of symbols available like .

Anything I missed, please make a suggestion.

7 Likes

Brilliant!

1 Like

And maybe this is obvious but a link to this section should be put in the Base.:== and Core.:=== sections in the Base docs, too, I think it’s just that important and common of a question to have.

2 Likes