[fpc-pascal] Feature announcement: Dynamic array extensions

Sven Barth pascaldragon at googlemail.com
Fri May 25 10:50:42 CEST 2018


Michael Van Canneyt <michael at freepascal.org> schrieb am Fr., 25. Mai 2018,
10:15:

>
>
> 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 ?
>

Correct :)

Similar for indices <= 0: they will always prepend (for strings <= 1 of
course).

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180525/cfa8a309/attachment.html>


More information about the fpc-pascal mailing list