[fpc-devel] New feature discussion: for-in loop
Sergei Gorelkin
sergei_gorelkin at mail.ru
Wed Oct 21 17:07:17 CEST 2009
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'.
Sergei
More information about the fpc-devel
mailing list