[fpc-devel] for-in-index loop

Michael Van Canneyt michael at freepascal.org
Sat Jan 26 13:28:48 CET 2013



On Sat, 26 Jan 2013, Alexander Klenin wrote:

> On Sat, Jan 26, 2013 at 10:34 PM, Michael Van Canneyt
> <michael at freepascal.org> wrote:
>> But if I must choose between
>>
>> for a,b in c do
>>
>> (with C a tuple enumerator/iterator) or
>>
>> for a in c index b do
>>
>> Then the former is ten times (well, a lot) better.
>>
>> So if someone were to introduce that to solve the original poster's problem,
>> you will not hear me protesting, it will have been well worth the energy I
>> put in this discussion.
>>
>
> There are two reasons I proposed latter instead of former:
> 1) I think using keyword is more explicit and readable
> 2) I thought that smaller feature is easier to argue for than a large one --
>  apparently, I was mistaken on that :)

Well, a tuple is simply a new fundamental type.

Just like generics, BTW.

> So, amended "for-in-index" proposal:
> 1) The syntax is
> for value, key in container do ...
> 2) The enumerator interface is extended with optional
> property CurrentWithKey: TValueKey;
> where TValueKey must be a record with two fields.

I don't think we need a record.

Lets first see about how to implement general tuple values before you start 
restricting it. I see Sven is already working on some ideas.

It may be more work up front, but it will be a more fundamental solution.

To be clear, the "for in index" syntax with 'index' keyword will not 
be recuperated.

No temporary workarounds/hacks. Decent solutions.

Michael.



More information about the fpc-devel mailing list