![]() |
Examples 7.2.4:
|
![]() |
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.
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 -
say - although, of course, no complex number arithmetic, etc operations would be possible (see the class CPX in the Required Library).
Two tuples of the same type (ie having the same actual type arguments) may be compared for equality using either the infix notation
The implementation-dependent result of applying this must, it will be remembered, be deterministic, thus
will always make eq true and it should also be true when using
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
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: Wednesday, 25 October 2000. |
![]() |