1
Other / Re: Unleashed Pascal (async/await, parallel for, match, string interpolation & more)
« Last post by Fibonacci on Today at 05:01:32 am »Pascal sets are ordinals
RTTI settles it: a set gets its own kind, tkSet, sitting next to tkDynArray among the structural types - not next to tkEnumeration among the ordinal ones. And the ordinal-only builtins reject it outright, while accepting the enum it was built from.
- program ordinals;
- {$mode unleashed}
- uses TypInfo;
- function TypeNameOf(ti: PTypeInfo): string;
- begin
- result := 'name: '+(if ti^.Name<>'' then ti^.Name else '-')+ ', kind: '+GetEnumName(TypeInfo(TTypeKind), Ord(ti^.Kind));
- end;
- type
- TDay = (mon, tue, wed);
- TDays = set of TDay;
- TArrI = array of Integer;
- var
- d: TDay;
- x: TDays;
- begin
- writeln('TDay = ', TypeNameOf(TypeInfo(TDay))); // tkEnumeration <- ordinal
- writeln('TDays = ', TypeNameOf(TypeInfo(TDays))); // tkSet <- structural
- writeln('TArrI = ', TypeNameOf(TypeInfo(TArrI))); // tkDynArray <- structural
- writeln;
- d := mon;
- writeln(Ord(d)); // ok - TDay is ordinal
- writeln(Succ(d)); // ok
- writeln(Low(TDay)); // ok - returns TDay
- //writeln(Ord(x)); // Error: Ordinal expression expected
- //x := Succ(x); // Error: Ordinal expression expected
- //x := Low(TDays); // Error: Incompatible types: got "TDay" expected "TDays"
- end.




Recent Posts