6 ms·
A feature that combines well with range and enum types are typed indexes of arrays: TYPE TWeekday = (Monday, Tuesday, Wednesday, Thursday, Friday, Saturda
by ainar-g 3y ago
A feature that combines well with range and enum types are typed indexes of arrays:
TYPE
TWeekday = (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
Sunday);
VAR
WeekdayNameIndex : ARRAY [TWeekday] OF ShortString = ('Mon', 'Tue',
'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
Now `WeekdayNameIndex` is a properly type- and range-checked look-up table.
It's really sad that these simple joys of Pascal are still lacking from a lot of mainstream languages.
- pjmlp 3y agoIndeed, I used that kind of stuff a lot.
- pyjarrett 3y agoThis is an awesome feature, combined with appropriate type and bounds checking and prevents so many errors. It can also avoid resorting to a heavier-weight map type. Ada has this as well, including using any arbitrary continuous range for array indexing which handles remapping indices for you. e.g. if the key range is 20-40 the language handles associating it with array indices for you.