[fpc-devel] RFC: Support for new type "tuple" v0.1

Sven Barth pascaldragon at googlemail.com
Sat Jan 26 20:36:52 CET 2013


On 26.01.2013 20:14, Michael Van Canneyt wrote:
>
>
> On Sat, 26 Jan 2013, Sven Barth wrote:
>
>> Hello together!
>>
>> Based on the results of the "for-in-index" thread I've decided to come
>> up with a draft for the Tuple type which is thought by many people to
>> be a better alternative to "for-in-index".
>>
>> Please note the following points:
>> * This is not the final specification for Tuples and thus open to
>> discussion (there are still some issues with this draft that need to
>> be solved)
>> * I won't implement this feature myself (at least not in the near
>> future) as I have other topics on my list (most importantly generics
>> once type helpers are commited), so Alexander is free to give the task
>> for implementation to his student.
>
> After a first read, looks OK. You seem to have thought of everything
> that needs to be described, except maybe extraction of a single element:
>
> b : tuple of (integer, integer);
> a : integer;
>
> begin
>    b:=(1,2);
>    a:=b[0]; // a = 1 after this.
> end;
>
> In this sense, it seems more like an array of const than as a record.

The question is whether we really need it. But if you think it's 
worthwhile then one can add it. But then we might also need support for 
"Length" and maybe also (just for the sake of completeness) "Low" and 
"High". And then there's also the question whether to start at 0 or 1...

>
> I would not do the extensions. The tuple is simply a logical, immutable
> grouping of values.

That's why I proposed them as extensions. I'm myself not very sure in 
allowing them or not, but I added them for Alexander's sake ;)

> I would also not allow operators other than := <> and =, because in
> expressions,
> when encountering a (, it is not clear what is meant.

Here are two possiblities:
* allow operator overloads only for named tuples, which would mean that 
only "t3 := t1 + t2" would be supported
* allow operator overloads also for anonymous tuples, which would mean 
that (like I wrote in open issues) "(d1, d2, d3, d4) := (d1, d2, d3, d4) 
+ (1.0, 2.0, 3.0, 4.0)" would be supported

The former is also the case for other types (e.g. sets, though there 
only a few operators (like **) can be overloaded), so this would be 
consistent...

Regards,
Sven




More information about the fpc-devel mailing list