Comparing Tuples

You can directly compare tuples with the usual comparison operators, <,>,=. Here are some examples:

Q: (1, 2, 3) < (2, 3, 4)
A: True
Q: ("a", "b", "c") < ("a", "b", "d")
A: True

The comparison proceeds through the elements from left to right, and the first pair of elements that fails the test ends the tuple comparison:

Q: ("abc", 17, 25, 4) < ("zzz", 17, 25, 4)
A: True

This is true even though the rest of the numbers are equal, because the test fails on the leftmost element comparison. In this sense, the comparison acts like it does with version numbers, where the leftmost digits are considered to have greater significance. Thus, if you have control over the ordering of the tuple, you should place the most "important" items earliest in the list.

The size of the tuples must be equal for the result to be defined. For instance,

Q: (1, 2, 3) < (4, 5)
E: The operator "less than" is not defined.

Also the types of the tuple elements must match:

Q: (1, 2, 3) < (4, 5, "a")
E: The operator "less than" is not defined.

Any comparisons with <nothing> will cause an error:

Q: (nothing) < (nothing)
E: A singular expression is required.

Q: (nothing) < (1)
E: A singular expression is required.

Q: (nothing, nothing) < (1)
E: A singular expression is required.

Q: (nothing, nothing) < (1,2)
E: A singular expression is required.

Q: (nothing , 1) < (nothing , 2)
E: A singular expression is required.

Q: (nothing , 1) < (1,2)
E: A singular expression is required.