[fpc-devel] New feature discussion: for-in loop

Michael Van Canneyt michael at freepascal.org
Wed Oct 21 17:18:30 CEST 2009



On Wed, 21 Oct 2009, Sergei Gorelkin wrote:

> Michael Van Canneyt wrote:
>> 
>> Hm.  I like this direction of thinking, yes...
>> 
>> What about
>>
>>   function StepNext: Boolean; iterator 'movenext';
>>   property TheCurrentValue: Integer; iterator 'current';
>> 
>> or better yet, because it is more strict:
>>
>>   function StepNext: Boolean; iterator nextvalue;
>>   property TheCurrentValue: Integer; iterator currentvalue;
>> 
>> In this way, it's more like some extra modifiers. (so like safecall, 
>> default, stored and whatnot)
>> 
>> It just adds some modifiers, and we're free of hard-coded names.
>> With one of these I could live :-)
>> 
> As I tried to say earlier, having distinct StepNext() and Current() functions 
> is somewhat redundant, except the purpose of Delphi compatibility.
> Rationale: the for..in loop manages the iterator object itself, and does not 
> allow user code inside the loop to access the iterator and call its  methods. 
> Therefore, it is possible to reduce the whole thing to:
>
> function Next(out value: SomeType): Boolean; iterator;
>
> thus eliminating the need for additional qualifiers after 'iterator'.

If this is possible, it is even better...

The main thing is: no hardcoded names...

Michael.



More information about the fpc-devel mailing list