Ideas for shortening "foreach_reverse" (was Re: I have a suggestion.)

Bill Baxter dnewsgroup at billbaxter.com
Thu May 17 16:29:24 PDT 2007


Sean Kelly wrote:
> Justin C Calvarese wrote:
>> YonggangLuo wrote:
>>> i think it's will be a good idea to replace "foreach_reverse" with  
>>> "frr".
>>> "foreach_reverse" is too long as a keyword
>>
>> I agree that foreach_reverse is way too long for a keyword. Also, it 
>> has that unslightly underscore.
>>
>> I think that frr is a little too short. Since it's a keyword that will 
>> be rarely used, newcomers to D will likely get confused.
>>
>> I'm "voting" for foreachrev, but here's a whole list of decent 
>> alternatives to the current "foreach_reverse" mess:
>>
>> 1. foreachrev
>> 2. rforeach
>> 3. revforeach
> 
> I still like:
> 
> foreach - unordered?
> foreach(fwd) - explicitly forward
> foreach(rev) - explicitly reverse
> foreach(any) - unordered
> 

Yep, or something of that ilk.  It's very D-like; it means we can get 
rid of the special-case keyword; and it leaves wiggle room for future 
innovation, like foreach(any), foreach(parallel), etc., without 
requiring more keywords.

The only thing better than that would be what Oskar said: to improve the 
compiler to the point that a construct like foreach(e; reversed(A)) 
could be as efficient as the current hard-coded foreach_reverse behavior.

--bb



More information about the Digitalmars-d-announce mailing list