Some Useful Modula-3 Interfaces

J. J. Horning, Bill Kalsow, Paul R. McJones et al. · 1996

ion failure. Different implementations of an abstract type may wish to supply different debugging information. By convention, we use the type AtomList.T for this purpose. The first element of the list is an error code; the specification of the subsequent elements is deferred to the subtypes. Portable modules should treat the entire parameter as an opaque type. An implementation module can minimize the probability of collision by prefixing its module name to each atom that it includes in the list. 1.5 Standard generic instances. Several of the interfaces in this manual are generic. Unless otherwise specified, standard instances of these interfaces are provided for all meaningful combinations of the formal imports ranging over Atom, Integer, Refany, and Text. For each interface that is likely to be used as a generic parameter, we define procedures Equal, Compare, and Hash. The procedure Equal must compute an equivalence relation on the values of the type; for example, Text.Equal(t, s) tests whether t and s represent the same string. (This is different from t = s, which tests whether t and s are the same reference.) If there is a natural total order on a type, then we define a Compare procedure to compute it, as follows: PROCEDURE Compare(x, y: X): [-1..1]; Return -1 if x R y and not Equal(x, y), 0 if Equal(x, y), and 1 if y R x and not Equal(x, y). (Technically, Compare represents a total order on the equivalence classes of the type with respect to Equal.) If there is no natural order, we define a Compare procedure that causes a checked runtime error. This allows you to instantiate generic routines that require an order (such as sorting routines), but requires you to pass a compare procedure as an explicit argument when calling the generic routine. The function Hash is a hash function mapping values of a type T to values of type Word.T. This means that (1) it is time-invariant, (2) if t1 and t2 are values of type T such that Equal(t1, t2), then Hash(t1) = Hash(t2), and (3) its range is distributed uniformly throughout Word.T. Note that it is not valid to use LOOPHOLE(r, INTEGER) as a hash function for a reference r, since this is not time-invariant on implementations that use copying garbage collectors.

Cited by 12 works.

Authors

References