[fpc-pascal] Feature announcement: Dynamic array extensions
Michael Van Canneyt
michael at freepascal.org
Fri May 25 10:15:42 CEST 2018
On Fri, 25 May 2018, Sven Barth via fpc-pascal wrote:
> Yes, that is what it does. Though a possible optimization would be that the
> compiler detects "dynarr := dynarr + [elem]" and converts it to
> "Insert(elem, dynarr, High(dynarr))".
>
>
>> Since dynamic array helpers work could you expose a function that adds an
>> element to the array (an grows it if needed) so we could make helpers for
>> it? Pushing a value to an array is perhaps the most common function used
>> for lists so it makes sense to get that right imo.
>>
>
> That function already exists and is called Insert() (see above).
Nice. I didn't know Insert() could be used to append to the end of a string.
One learns every day ! One for the documentation :-)
To be clear: for strings you can do
var
S : String;
begin
S:='123';
Insert('456',S,Length(S)+2);
Writeln(S);
end.
and it will append. Is the same true for dynamic arrays ?
i.e. any insert position >= length will do an append ?
Michael.
More information about the fpc-pascal
mailing list