tuple comparison

Thomas Lindgren <>
Wed Jul 27 18:02:21 CEST 2005



--- Serge Aleynikov <> wrote:

> I have a couple of questions that are not very
> obvious from documentation.
> 
> 1. When we compare two tuples of equal sizes,
> 
> T1 = {I1, I2, ..., In},
> T2 = {J1, J2, ..., Jn},
> 
> if T1 > T2 then
> 
> is there a guarantee that the following always holds
> true:
> 
> (I1 >= J1) and (I2 >= J2) and ... (In >= Jn)

No, for instance 
{2,1} > {1,2} 
 and 
{1,1,2,1} > {1,1,1,2}.

See below for more.

> 2. What's the meaning of such a result:
> 
> 53> {1, 2, 3} > 10.
> true
> 
> I would think that this comparison should throw an
> exception.

Comparisons operate over all terms.

Section 2.5.6 in the Erlang book gives an informal
ordering of the terms. It says "tuples are ordered
first by their size, then by their elements". Okay.
The Erlang 4.7 spec basically says comparisons reflect
term order, and 'term order' is lexicographic over
tuples (p.45, 4.11.2).

Best,
Thomas



		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 



More information about the erlang-questions mailing list