[fpc-pascal] Feature announcement: Dynamic array extensions
Michael Van Canneyt
michael at freepascal.org
Fri May 25 07:43:49 CEST 2018
On Fri, 25 May 2018, Ryan Joseph wrote:
>
>
>> On May 25, 2018, at 1:37 AM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>>
>> This is currently not supported. And to avoid backwards compatibility problems with existing operator overloads you'd probably need to convert it to a dynamic array first:
>>
>> === code begin ===
>>
>> a += ['foo'];
>>
>> === code end ===
>
> What is that doing being the scenes? If it’s creating a whole new array and appending it then it’s probably pretty inefficient and hopefully can be optimized away.
>
> 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.
I think the above is "right", and completely equivalent to sets, which are in some ways
like an array: a "collection" of same typed values.
To add an element to a set you also do
MySet:=MySet+[aValue];
That said, sets do have
Include(MySet,AValue);
to include a single value.
Maybe this syntax can be extended to dynamic arrays.
Michael.
More information about the fpc-pascal
mailing list