[fpc-devel] New feature discussion: for-in loop
Paul Ishenin
webpirat at mail.ru
Sun Oct 25 06:49:19 CET 2009
Graeme Geldenhuys wrote:
> Just to recap... What exactly does the function GetEnumerator return?
> Specifically for list type classes. Also what interface would that
> enumerator support?
>
Valid return for now is object or class instance. I did not implement
interface support yet. But delphi has the next interface for this:
IEnumerator = interface(IInterface)
function GetCurrent: TObject;
function MoveNext: Boolean;
procedure Reset;
property Current: TObject read GetCurrent;
end;
> The reason I ask... I would still like the full power of Iterator (as
> discussed before) for all List type classes in the RTL (similar to my
> code attachment of 4 days ago). I'm not sure if what you implemented
> will conflict with what I want to implement in the RTL. The major
> difference would be that mine is a implementation detail in the list
> classes, whereas your implementation is a language feature. When I use
> iterators, I would like to have the ability to use Current, HasNext,
> HasPrevious, PeakNext, PeakPrevious, Reset, JumpToBack, pass a filter
> to GetIterator... etc.
>
I don't argue but how do you think to use HasPrevious, PeakNext,
PeakPrevios, Reset, JumpToBack in the for-in loop? Can you suggest a syntax?
> Also, I referred to them in my implementation as Iterators - as per
> the Iterator design pattern. How does Enumerator differ from Iterator?
>
Delphi enumerator pattern is a structure with one boolean function
MoveNext and one property Current.
More info is here:
http://17slon.com/blogs/gabr/2007/03/fun-with-enumerators.html
Best regards,
Paul Ishenin.
More information about the fpc-devel
mailing list