[fpc-devel] New feature discussion: for-in loop
Alexander Klenin
klenin at gmail.com
Wed Oct 21 17:24:34 CEST 2009
On Thu, Oct 22, 2009 at 02:07, Sergei Gorelkin <sergei_gorelkin at mail.ru> wrote:
> 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'.
This is slightly better, but IMO does not worth additional incompatibility.
Also, your proposal is far less extendable:
1) Delphi iterators have also magic 'Reset' function which is easy to
express by attribute "iterator reset",
but hard to express in your proposal
2) See the end of the for-in wiki page for my proposal for optional
"iterator index" extension,
which is also non-trivial to do in your proposal.
--
Alexander S. Klenin
More information about the fpc-devel
mailing list