# Examples 7.2.4:
TUP

The features of the pervasive class family TUP are used in individual examples. The instance defined in that definition of a two-component tuple is used here. The extension to more components follows the same pattern. None of the examples given is a complete class nor necessarily a 'complete' method.

#### create

Creation of a tuple is carried out using this routine which sets the two public attributes to have the values of the two components. Thus, given two real number types, it would be possible to come up with a very simplified complex number type object by writing -

my_cpx_val : TUP{FLT,FLT} := TUP{FLT,FLT}::create(1.0, -1.0)

say - although, of course, no complex number arithmetic, etc operations would be possible (see the class CPX in the required library).

#### is_eq

Two tuples of the same type (ie having the same actual type arguments) may be compared for equality using either the infix notation

other_cpx_val : TUP{FLT,FLT} := TUP{FLT,FLT}::create(1.0, -1.0)
eq : BOOL := my_cpx_val = other_cpx_val ;

#### hash

The implementation-dependent result of applying this must, it will be remembered, be deterministic, thus

eq := my_cpx_val.hash = my_cpx_val.hash

will always make eq true and it should also be true when using

cpx_val : CPX := CPX::create(1.0,-1.0) ;
other_cpx_val := TUP{FLT,FLT}::create(cpx_val.re,cpx_val.im) ;
eq := my_cpx_val.hash = other_cpx_val.hash

#### str

This feature provides a string representation of the value of the tuple. Since it is primarily designed for handling conjuncts of immutable classes, the exact form of this is dependent on the actual class arguments and, of course, on the culture and encoding in which the program is executing. The statement

rep : STR := my_cpx_val.str

will probably result in rep having a value something like '[1.0,-1.0]' or, in Europe, perhaps '[1,0.-1,0]'. If the tuple class arguments had been, say, a couple of reference classes for which no string representation is available then the string could be something like '[*,*]' - more as a place-holder than a useful representation in this case.

| Specification Index |  | Language Index |  | Section 7 Index

Comments or enquiries should be made to Keith Hopper . Page last modified: Tuesday, 23 May 2000. |