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

Graeme Geldenhuys graemeg.lists at gmail.com
Tue Oct 20 10:40:38 CEST 2009


2009/10/20 Alexander Klenin <klenin at gmail.com>:
>> I just read the docs in the lazarus wiki. The problems/limitations
>> still hold true. For-in only goes in ONE direction
>
> Hm, did you read the about reverseEnumerators and various irders of
> tree traversals?

-------------------
// for basic type we will call only the apropriate function
procedure TraverseString(S: String);
var
  C: Char;
begin
  for C in S using GetReverseStringEnumerator(S) do
    DoSomething(C);
end;
-------------------

Now your for-in syntax changes because you want to use different
enumerators. Why? It's not very elegant having to change your code,
based on what you are iterating. That tells me it's not flexible
enough. With the Iterators I wrote, you only have ONE interface you
have to work with, no matter what type of list you are iterating or if
the returned results are filtered or not.



>> and can't peak
>
> That is true, but this is required in maybe 1% of the cases, or even less.
> For these cases, certainly slightly longer while loop is justified.

Lets say you want to parse a UTF-8 string. Or you want to parse text
for a documentation generator, or you want to strip text from an HTML
file or Wiki page. All uses of where Peak is very often used. And
that's just a short list of the top of my head.


>
> Please read again with more attention ;-)

BTW: The wiki pages does not contain the word "reverseEnumerators" as
you suggested earlier.



-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-devel mailing list