Data types: Set type

Represents any combination of values defined in a certain set member.

Type syntax

unit‑name::set‑name

Literal syntax

unit‑name::set‑name[item‑name,item‑name, ... ]

unit‑name::set‑name[]

Discussion

Operands of this data type can be considered as collections containing none, one or any combination of values defined in a certain set member. Each value can be individually included or excluded. Chora compiler ensures, that the operands are never initialized with values belonging to foreign set members.

A set data type must always consist of two identifiers: the name of the unit containing the set member and the name of the set member itself, both separated by :: (double colon). The type is designated to be used in declarations of data members able to store the set values. The literal, in turn, consists of the set data type followed by the list of set items enclosed between a pair of [...] (square brackets) and separated by a , (comma) signs. The order of items doesn't matter. Literals with no items (no names between [ ... ]) are considered as empty sets. For example:

// 'layout' can store values from the 'Core::Layout' set. 
// For the moment the set is empty.
var Core::Layout layout = Core::Layout[];

// now 'layout' includes two items: 'AlignToTop' and 'ResizeVert'.
layout = Core::Layout[ AlignToTop, ResizeVert ];

Instant properties

You can test whether a set operand is empty or not by simply evaluating its instant property isempty.

Instant methods

You can test whether one set operand is completely contained within another set operand by using the instant method contains().

Set operations

You can combine two set operands to expressions. The following table provides an overview of the possible operations:

Operator

Abstract description

+

Union of two set operands.

-

Difference between two set operands.

&

Intersection between two set operands.

Comparison operations

You can compare two set operands in order to test whether these contain exact the same items or not. The following table provides an overview of the possible operations:

Operator

Short description

==

Equality test for two set operands.

!=

Inequality test for two set operands.

Type conversions

Chora reacts sensitive when mixing operands of different data types within an operation. To avoid compiler warnings or even errors you can convert between set and integer operands explicitly.