How does the Erlang comparison operator work exactly?

erlang

Solution

- `A` has the ASCII code 65, `a` has the ASCII code 97 thus `"A" < "a"`.

- To quote the inventor: "The actual order is not important - but that a total ordering is well defined is important". This is because you want all terms to be comparable as only in that case you can sort them (which is often of use).

The exact rules are given in http://www.erlang.org/doc/reference_manual/expressions.html#id77480:

7.11 Term Comparisons

The following order is defined:

number < atom < reference < fun < port < pid < tuple < list < bit-string

Lists are compared element by element. Tuples are ordered by size, two tuples with the same size are compared element by element.

Problem

Sorry for such basic question but I can't figure this out: If I use normal relational comparison operators with terms - how does it work exactly? For example: `"AAA" > "aaa" => false` - Why is `"AAA"` less than `"aaa"`? If I have two atoms: `atom1 < atom2 => true` - Why is `atom1` less than `atom2`? How/when do I use the comparison operators with atoms?

Original source