I have a suggestion.

Oskar Linde oskar.lindeREM at OVEgmail.com
Wed May 16 12:57:30 PDT 2007


BCS skrev:
> antonio wrote:
>> I think the more "algebraic" way could be something like
>>
>> foreach(int i; reversed array)
>>
>> compiler must act in the optimal way.
>>
> 
> or we could take a hint from scope and do:
> 
> foreach(reverse)(i;arr)
> 
> that leaves the door open for things like
> 
> foreach(stride, 5)(i;arr) {}
> 
> and
> 
> foreach(heaptree)(i;arr) {}
> 
> the overloads could be something like
> 
> opApply(char[] : "reverse")(int delegate(inout int));
> 

Not that I havn't said it before, but there doesn't need to be any 
language changes at all. Removing foreach_reverse altogether doesn't 
remove any expressiveness -- just a special case.

If the compiler was smart enough to 1) be able to inline functions with 
loops, and 2) be able to inline const (at compile time known) delegate 
calls (which it possibly does already), there would be no need for this 
special case keyword.

foreach(i; arr), foreach(i; reverse(arr)), foreach(i; heaptree(arr)), 
and so on, could all be equally efficient.

/Oskar



More information about the Digitalmars-d-announce mailing list