[fpc-devel] for-in-index loop

Michael Van Canneyt michael at freepascal.org
Fri Jan 25 19:32:52 CET 2013



On Fri, 25 Jan 2013, Sven Barth wrote:

> On 25.01.2013 17:18, Alexander Klenin wrote:
>> With this in mind, consider a user who wants to iterate over the
>> following array:
>> 
>> var
>>    a: array [1..5] of Integer = (1, 2, 9, 4, 5);
>> 
>> In my proposal, he should write:
>> var
>>    v, i: Integer;
>> begin
>>    for a in a index i do
>>      Writeln(i, ' ', v);
>> end.
>> 
>> In your proposal, he should write (suppose GIter is a unit
>> implementing the generic array iterator):
>> uses
>>    GIter;
>> type
>>    TArrayIntIterator = specialize TArrayIterator<Integer>;
>>    i: TArrayIntIterator.TElem;
>> begin
>>    for i in TArrayIntIterator.Create(a) do
>>      Writeln(i.Index + Low(a), ' ', i.Value);
>> end.
>
> One could also do an alternative (though currently not with arrays, but with 
> type helper support even that would be possible...):

Talk about a choice between the plague and cholera...

If I must choose between the proposed extension of for in index do
and having anonymous functions, then I choose for for in index :)
(and most likely ending up with both monstrosities)

Pascal is an explicitly declarative language. 
Anonymous functions go 100% against this. 
It is the readability horror I associate with Javascript.

I often wonder: why do people who seem to think that Pascal misses 
so many - apparently essential - things, even bother to use it ?

If I thought Pascal was missing so many things, I would simply 
use something else instead of trying to turn it into something 
that it is not.

Michael.



More information about the fpc-devel mailing list