没有字段名称的 ISO Pascal 记录变体
ISO Pascal record variants without a field name
我在尝试计算 ISO Pascal 的一部分时有点困惑。
语法允许你这样做:
type RPoint = Record
Case Boolean of
False : (X,Y,Z : Real);
True : (R,theta,phi : Real);
end;
要构建它,您需要:
var p: RPoint;
begin
p.x := 1;
end.
有一部分我不明白:Case Boolean
部分的目的是什么?我知道你可以 case MyVal: Boolean
;然后 MyVal
成为字段选择器。但是,如果没有字段选择器,只有一个类型,有什么用呢?
此外,标准说:
With each variant-part shall be associated a type designated the selector-type possessed by the
variant-part . If the variant-selector of the variant-part contains a tag-field, or if the case-constant-
list of each variant of the variant-part contains only one case-constant, then the selector-type shall
be denoted by the tag-type, and each variant of the variant-part shall be associated with those
values specified by the selector-type denoted by the case-constants of the case-constant-list of the
variant . Otherwise, the selector-type possessed by the variant-part shall be a new ordinal-type that
is constructed to possess exactly one value for each variant of the variant-part, and no others, and
each such variant shall be associated with a distinct value of that type.
我不太明白 selector-type
是什么以及为什么它会是一个新的 ordinal-type
。 selector-type
不就是 case Boolean of
中的类型吗?每个 case-constant-list
只有一个 case-constant
与它有什么关系?
这里你的变体记录有两个可能'personalities'。 Boolean 是一种具有两个可能值的类型。所以,这似乎是一个合乎逻辑的选择。但是,它不一定是布尔值。
您可以使用其他一些序数类型(例如 Integer 或 Byte)来获得相同的效果。例如:
type RPoint = Record
Case Byte of
0: (X,Y,Z : Real);
1: (R,theta,phi : Real);
end;
我在尝试计算 ISO Pascal 的一部分时有点困惑。
语法允许你这样做:
type RPoint = Record
Case Boolean of
False : (X,Y,Z : Real);
True : (R,theta,phi : Real);
end;
要构建它,您需要:
var p: RPoint;
begin
p.x := 1;
end.
有一部分我不明白:Case Boolean
部分的目的是什么?我知道你可以 case MyVal: Boolean
;然后 MyVal
成为字段选择器。但是,如果没有字段选择器,只有一个类型,有什么用呢?
此外,标准说:
With each variant-part shall be associated a type designated the selector-type possessed by the variant-part . If the variant-selector of the variant-part contains a tag-field, or if the case-constant- list of each variant of the variant-part contains only one case-constant, then the selector-type shall be denoted by the tag-type, and each variant of the variant-part shall be associated with those values specified by the selector-type denoted by the case-constants of the case-constant-list of the variant . Otherwise, the selector-type possessed by the variant-part shall be a new ordinal-type that is constructed to possess exactly one value for each variant of the variant-part, and no others, and each such variant shall be associated with a distinct value of that type.
我不太明白 selector-type
是什么以及为什么它会是一个新的 ordinal-type
。 selector-type
不就是 case Boolean of
中的类型吗?每个 case-constant-list
只有一个 case-constant
与它有什么关系?
这里你的变体记录有两个可能'personalities'。 Boolean 是一种具有两个可能值的类型。所以,这似乎是一个合乎逻辑的选择。但是,它不一定是布尔值。
您可以使用其他一些序数类型(例如 Integer 或 Byte)来获得相同的效果。例如:
type RPoint = Record
Case Byte of
0: (X,Y,Z : Real);
1: (R,theta,phi : Real);
end;