Originale-mail to me for new edition

 

Set operators

 

The following operators take sets as operands.

 

Operator

Operation

Operand types

Result type

Example

+

union

set

set

Set1 + Set2

-

difference

set

set

S – T

*

intersection

set

set

S * T

<=

subset

set

Boolean

Q <= MySet

>=

superset

set

Boolean

S1 >= S2

=

equality

set

Boolean

S2 = MySet

<>

inequality

set

Boolean

MySet <> S1

in

membership

ordinal, set

Boolean

A in Set1

 

The following rules apply to +, -, and *.

·  An ordinal O is in X + Y if and only if O is in X or Y (or both). O is in X - Y if and only if O is in X but not in Y. O is in X * Y if and only if O is in both X and Y.

·  The result of a +, -, or * operation is of the type set of A..B, where A is the smallest ordinal value in the result set and B is the largest.

 

The following rules apply to <=, >=, =, <>, and in.

·  X <= Y is True just in case every member of X is a member of Y; Z >= W is equivalent to W <= Z. U = V is True just in case U and V contain exactly the same members; otherwise, U <> V is True.

·  For an ordinal O and a set S, O in S is True just in case O is a member of S.

 

Topic groups

 

See also

About operators

Operator precedence rules

 

 

译文

 

集合运算符

 

下列运算符接受集合为操作数:

 

运算符

操作

操作数类型

结果类型

范例

+

并集

集合

集合

Set1 + Set2

-

差集

集合

集合

S – T

*

交集

集合

集合

S * T

<=

子集

集合

Boolean

Q <= MySet

>=

超集

集合

Boolean

S1 >= S2

=

相等

集合

Boolean

S2 = MySet

<>

不等

集合

Boolean

MySet <> S1

in

成员

序数,集合

Boolean

A in Set1

 

下列规则适用于+-* 等运算符:

·  序数OX + Y的成员,当且仅当OX的成员或OY的成员(或者都是)。OX - Y的成员当且仅当OX的成员并且不是Y的成员。OX * Y的成员当且仅当OX的成员并且OY的成员。

·  运算符+-*对集合运算的结果形如set of A..B,这里的A是结果中最小的序数,B是最大的序数。

 

下列规则适用于<=>==<>in等运算符:

·  X中的每个成员都是Y的成员时,X <= Y的结果为TrueZ >= W 等价于W <= Z;当UV包括完全相同的成员时,U = V的值为True,否则U <> V的值为True

·  对于序数O和集合S,当OS的成员时,表达式O in S的值为True

 

主题组

 

相关主题

运算符

运算符优先规则

 

 

编者注

 

序数(Ordinal)和序数型(Ordinal Types)并非仅指如ByteWordInteger等整数和整数类型,也包括CharBoolean等类型。因此“序数”也并非仅指“数”。下面的代码举例说明了序数和集合的类型定义、变量声明和一般使用:

 

type

  TMyBoolean = Boolean;

  TMyBooleanSet = set of TMyBoolean;

 

  TWeekDay = (Mon, Tue, Wed, Thu, Fri, Sat, Sun);

 

  TOffDays  = set of TWeekDay;

  TWorkDays = set of TWeekDay;

 

var

  BSet: TMyBooleanSet;

  ODays: TOffDays;

  WDays: TWorkDays;

 

...

 

  BSet := [True];

  ODays := [Sat, Sun];

  WDays := [Mon, Tue] + [Wed, Thu, Fri] + ODays - [Sun];

 

...