Wish: default parameters for LOW and HIGH intrinsic functions
Low/High function are useful when writing portable and future-proof code. Sadly, they need a lot of boilerplate...
For example, let's compile the lazarus\components\lazutils\laz2_xmlread.pas in type-safe mode ({$T+} AKA -Sy).
Because freepascal.org/lazarus/lazarus#40263 (closed) for example.
FStdPrefix_xml := FNSHelper.GetPrefix(@PrefixDefault, 3);
laz2_xmlread.pas(1650,55) Error: Incompatible type for arg no. 1: Got "^Array[0..4] Of Char", expected "PChar"
And indeed, const PrefixDefault: array[0..4] of DOMChar = ..., Pascal is not C and arrays are not pointers.
The correct code would be
FStdPrefix_xml := FNSHelper.GetPrefix(@PrefixDefault[Low(PrefixDefault)], 3);
But that is a lot of boilerplate, visual noise. It also vialoates the DRY principle opening the code to "copy-paste errors" like
FStdPrefix_xml := FNSHelper.GetPrefix(@PrefixDefault[Low(PostfixDefault)], 3);
It would be nice if one could just write @PrefixDefault[Low()] or @PrefixDefault[Low] having Low's parameter been inferred from the call site.
This should apply to all range/set types (arrays being a construct built upon range).
var n: d..e;
begin
n := High(); // meaning n := High(n);
and
type T = set of X;
var m: T; z: X;
m := Low();
The above should be the same as m := Low(T) / m := Low(X) and, if possible, same as m := Low(m).
But then z := Low(m); should, if possible, and unlike mere Z := Low(); described above in "range" section, should mean the minimal element of M set same way as in "for z in m do`;
Granted, this implies result-type overloading, which is impossible in Delphi. But in FPC it was already implemented in record operators, and was said to work reliably in practice, so perhaps could be possible for Low/High distinguishing as well.
Also
var s: string;
...
if s[Length()] <> PathDelim then s := s + PathDelim;