Sather Home
        Page

Section 7.2.4:
TUP

immutable class TUP{...}
NOTE The TUP 'constructor' mechanism specified here is a value constructor defined for any number of class arguments of arbitrary classes/types. The result is thus a family of types. The language defines this in a similar way to record types in other languages. There are no restrictions on how such a type is to be implemented. In particular, the implementer is free to arrange value in store in any convenient way. See, however, external classes where placement is required.

Formal Types

There is no way in which this type can be specified formally in vdm-sl, since it is effectively an infinite set of types. The expressions below are therefore written to express the intent of the definition rather than a completely correct definition for any one instance of the type family.

types

SAME = TUP{...} ;

TUP{...} ::
t1 : T1
... : T...
tn : Tn

immutable class TUP{T1,T2}

This particular class is defined here as an example of tuple construction. The features given below are defined for each variant, the sole change being the number of attributes and the number of arguments to the creation routine.

Note that the provision of the 'hash' and 'str' features in this pre-defined class is expected to mean that an implementer defines this class to inherit from $HASH and $STR. This is not, however, a requirement of the language.

attr t1 : T1 ;

attr t2 : T2 ;

This variant of a tuple class defines two read/write components.


create

Application of the create feature returns a new tuple irrespective of the values of the parameters given.

create (
first : T1
second : T2
) : SAME
Formal Signature

Note that neither the parameters nor result are optional types and cannot therefore be nil.

create(first : T1, second : T2) res : SAME
Post-condition
post (t1(res) = first)
and (t2(res) = second)

This routine creates a two-component tuple with the given argument values.


is_eq

The equality of two tuples relies on all component equality tests being true.

is_eq (
other : SAME
) : BOOL
Formal Signature
is_eq(self : SAME, other : SAME) res : BOOL
Post-condition
post (t1(res) = t1(other))
and (t2(res) = t2(other))

This predicate returns true if and only if both (all) of the components of self and other are equal. Note that this predicate may be used in an infix logical expression.


hash

This hash feature should provide a deterministic numeric result which, for any particular tuple, has an equal probability of being any value in the cardinal number domain.

Note that the return type of this function is given as nat for the use of those implementers who do not wish to implement the Required Library. Where an implementatiion does include the Required Library then this is to be replaced for implementation purposes by the Required Library class CARD.

hash : nat
Formal Signature
hash(self : SAME) res : nat
Post-condition

The result of applying this feature is a deterministic implementation-defined value.

This routine returns a simple hash value computed from the component hash values of the tuple. The computation is implementation-defined except insofar as it must be deterministic.


str

This representation feature is dependent on the culture (and encoding) in which the program is currently executing.

str : STR
Formal Signature
str(self : SAME) res : STR
Post-condition

The result of applying this feature is a text string, the encoding and character repertoire of which are determined by the system and culture in which the program is executing. The requirement for a size of at least five in this particular variant provides for two bracketing and one separating glyph in addition to a minimum of one representing each value.

post STR.size(res) >= 5

This routine returns a string representation of the tuple using the default repertoire and encoding.


Language Index Library Index Section 7 Index
Comments or enquiries should be made to Keith Hopper.
Page last modified: Wednesday, 25 October 2000.
Produced with Amaya