Type declarationsSet typesSet types have values that specify a subset of a set of objects. The objects can be:
To specify a set type, use: SET OF TypeSpecification; PACKEDSET OF TypeSpecification; TypeSpecification is called the base type of the set. You can think of a set type as having a Boolean membership flag for each value in the base type. Modula-2 supports two different types of sets, SET and PACKEDSET. The only difference between the two is how a compiler is allowed to implement a set type. PACKEDSET types are implemented such that each ordinal value in the set maps directly to individual bits in the memory storage for the set type. The first ordinal value occupies the first bit and this continues until the last bit. A compiler is allowed to implement the SET type in any way it chooses. Note: Stony Brook Modula-2 implements the SET type the same as the PACKEDSET type. Example: SET OF CHAR SET OF [0..65535] SET OF ['A'..'Z'] SET OF (Red, Green, Blue) An object with the type of the last example above can have any of the following values: {} Source:
|