Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo Pascal - <b> set set type pp 88</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 SET                               Set Type                            pp 88


 Define:  A set is a collection of related objects which may be thought of
          as a whole.  A set type is introduced by the reserved words
          Set Of followed by a simple type.

 Purpose: Provide a collective means of referring to related objects.

 Notes:   Each object in a set is called a member or element of
          that set.  The members of a set must all be of the same type,
          called the base type, which must be a simple scalar type.

          Set expressions consist of set constants, set variables,
          set constructors and set operators.

 Terms:
          Set Constructor
          A set constructor consists of one or more element
          specifications separated by commas and enclosed in square
          brackets.

          Element Specification
          An element specification is an expression of the same type
          as the base type of the set, or a range expressed as two
          such expressions separated by two periods (..).

          Equality
          The equality of two sets, written as Set1 = Set2.
          Two sets are equal only if all their members are the same.
          The ordering of the members is not a concern.
          [1,3,5]  [5,3,1]  [1,5,3] are all equal.

          Union
          The sum of two sets, written as Set1 + Set2.
          [1,3,5,7] + [2,4,6] = [1,2,3,4,5,6,7]

          Intersection
          The product of two sets, written as Set1 * Set2.
          [1,3,5,7] * [2,3,4] = [3]

          Relative Complement
          The subtraction of Set2 from Set1 written as Set1 - Set2.
          [1,3,5,7] - [2,3,4] = [1,5,7]

          Empty Set
          The set with no members, written as [].


 Operators:
          *  - Intersection
          +  - Union
          -  - Difference

          =  - Equality
          <> - Inequality

          >= - True if all of Set2 are in Set1  { Set1 >= Set2)    }
          <= - True if all of Set1 are in Set2  { Set1 <= Set2)    }

          [] - Set Disjunction                  { Set1 * Set2 = [] }
          IN - Set membership.                  { Set1 IN Set2)    }
                     The second operand is of a set type.
                     The first operand is an expression of the same type.
                     The result is True if the first operand is a member
                     of the second operand (set).




 ----------------------------------------------------------------------------


 Usage:
       CONST
          Yes_Set    : Set Of Char = ['Y','y']  ; { Set of two values       }
          UpperCase  : Set Of Char = ['A'..'Z'] ; { Uppcase case letters    }
          WhiteSpace : Set Of Char = [#9,#10,#12,#13,#32];

       TYPE
          CharSet    = Set Of 0..255 ;            { Set type is Byte        }

       VAR
          Lower      : CharSet       ;            { All are of type CharSet }
          Upper      : CharSet       ;
          Result     : CharSet       ;
          Null       : CharSet       ;

       BEGIN
          Null       := []           ;            { Empty set is no members }
          Lower      := [0..127]     ;            { Members = 000 to 127    }
          Upper      := [128..255]   ;            { Members = 128 to 255    }
          Result     := Upper * Lower;            { Members = []            }
          Result     := Upper - Lower;            { Members = 128 to 255    }
          Result     := Upper + Lower;            { Members = 000 to 255    }
       END.

See Also: Const

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson