[OT] foreach(scheme) (Was: Differentiate const flavors using CASE?)

kris foo at bar.com
Wed Mar 21 22:47:35 PDT 2007


Daniel Keep wrote:
> 
> kris wrote:
> 
>>janderson wrote:
>>
>>>Andrei Alexandrescu (See Website For Email) wrote:
>>>
>>>>
>>>>Yah :o). Speaking of foreach_reverse, probably it would be wise to
>>>>lobby Walter to deprecate it in favor of foreach(reverse) (item ;
>>>>collection) { ... }. The keyword(extra) syntax is definitely becoming
>>>>a D signature syntax.
>>>>
>>>>
>>>>Andrei
>>>
>>>
>>>//Using your other suggestion:
>>>foreach(reverse) (item ; collection) (item2 ; x->GetColection(b))
>>>(item3 ; collection3)
>>>{
>>>
>>>}
>>>
>>>Its starting to get hard and harder to read IMO.
>>>
>>>Although perhaps the reverse could be come sort of iterator mechanism.
>>>You could define what order items are visited.  I mean, reverse would
>>>not be a keyword at all and would exist in some library.  Although I'm
>>>not sure how it would be implemented, and it may defeat the purpose of
>>>foreach_reverse being optimal.
>>>
>>>Just a thought.
>>
>>shouldn't this perhaps be something like:
>>
>>foreach (item; collection) (item2; x->GetColection(b))(item3;
>>collection3.reverse)
>>{
>>
>>}
>>
>>
>>Now you can select a direction on the each container?
>>
>>Naturally, this would avoid performing a copy of the content, and the
>>basic approach is quite easy to handle via a struct containing an
>>opApply(). It would open the door to alternate iteration approaches
>>also, such as skipping entries, merging, or whatever.
>>
>>Tango does something vaguely like this for the text-iterators in
>>tango.text.Util
> 
> 
> What if collection3 is a 40 MB array?
> 
> The nice thing about foreach_reverse is that it doesn't require any
> transformations on the data.  

I didn't suggest transformation at all :) Merely a mean of satisfying 
opApply that happens to go backwards instead (or some other pattern).

Please, take a peek at tango.text.Util ... methods lines(), delimiters() 
and patterns() are examples of what I'm getting at. That particular 
approach can easily be adapted for any kind of container



More information about the Digitalmars-d mailing list