[fpc-devel] New feature discussion: for-in loop
Graeme Geldenhuys
graemeg.lists at gmail.com
Sun Oct 25 09:46:54 CET 2009
2009/10/25 Paul Ishenin <webpirat at mail.ru>:
>
> To use it in the for-in loop you need to add a function MoveNext: Boolean
> (you can choose any other name but you need to mark it using 'enumerator
> MoveMext' modifier) and property Current: TObject (you can choose any other
> name but you need to mark it using 'enumerator Current' modifier).
Thanks Paul, now I have a much better idea of for-in loop (I started
getting confused during this message thread discussion and lost
track). As I mentioned in my previous post, I did not expect my idea
of Iterators to work with for-in. Looking at your examples, I still
agree with my assessment.
for-in can be considered a "lite" version of Iterators. The for-in
syntax however does not replace the need for full Iterator support. By
"full Iterator" I mean having a large set of methods that the user can
use, like: PeakNext, PeakPrevious, Remove, JumpToBack, etc...
So I will continue with my work of Iterator support in all RTL
container classes and use the GetIterator method to create an Iterator
instance. This means the user can decide which method they want to use
to iterate over their container classes and how much control they need
in the looping code. It they only need a front-to-back loop, they can
use for-in syntax,but if they want more control, they can request a
Iterator via GetIterator method.
BTW:
Reading that Delphi article about Enumerators, I must say that your
Implementation seems a lot more flexible by not hard-coding method
names etc... Clearly it pays to discuss ideas first before jumping
into the implementation. CodeGear certainly can learn something from
FPC developers! :-)
--
Regards,
- Graeme -
_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
More information about the fpc-devel
mailing list