Node:set, Next:, Previous:Self, Up:Reference



set

Synopsis

In type definitions:

set of Type  { built-in type class }

Description

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. 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.

Example


program SetDemo;

type
  TCharSet = set of Char;

var
  Ch: Char;
  MyCharSet: TCharSet;
begin
  MyCharSet := ['P','N','L'];
  if 'A' in MyCharSet then
    WriteLn ('Wrong: A in set MyCharSet')
  else
    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);
end.

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

See also

Keywords, Set Operations, in, Exclude, Include.