Next: , Previous: Self, Up: Reference



In type definitions:

     set of ordinal_type  { built-in type class }


A set contains zero or more elements from an ordinal type, e.g. Char, a subrange of Char, or a subrange of an enumerated type or integers. The elements of a sets do not have any ordering (that is a set containing 'B' and 'A' is the same as a set containing 'A' and 'B'), nor can an element be included more than once. Sets simply store the information about which elements are included in the set.

Conforming to

set is defined in ISO 7185 Pascal and supported by all known Pascal variants.


     program SetDemo;
       TCharSet = set of Char;
       Ch: Char;
       MyCharSet: TCharSet;
       MyCharSet := ['P','N','L'];
       if 'A' in MyCharSet then
         WriteLn ('Wrong: A in set MyCharSet')
         WriteLn ('Right: A is not in set MyCharSet');
       Include (MyCharSet, 'A');  { A, L, N, P }
       Exclude (MyCharSet, 'N');  { A, L, P }
       MyCharSet := MyCharSet + ['B','C'];  { A, B, C, L, P }
       MyCharSet := MyCharSet - ['C','D'];  { A, B, L, P }
       WriteLn ('set MyCharSet contains:');
       for Ch in MyCharSet do
         WriteLn (Ch);

Set also Set Operations or examples of some of the many set operations.

See also

Keywords, Set Operations, in, Exclude, Include.