Super-dee-duper D features

Aarti_pl aarti at interia.pl
Wed Feb 14 00:46:49 PST 2007


Andrei Alexandrescu (See Website For Email) napisał(a):
> James Dennett wrote:
>> C++, of course, has std::for_each(e.begin(), e.end(), do_x);
>> in its library (though that's weaker than it could be because
>> of lack of support for convenient anonymous functions/lambdas).
>>
>> C++0x is very likely to have for(v: e).  It's implemented
>> in ConceptGCC already. Java already has essentially that,
>> as does C#.  This really doesn't set D apart (but at least
>> D isn't falling behind here).
> 
> BTW, D might soon have simultaneous iteration that will blow away all 
> conventional languages:
> 
> foreach (i ; coll1) (j ; coll2)
> {
>   ... use i and j ...
> }
> continue foreach (i)
> {
>   ... coll2 finished; use i ...
> }
> continue foreach (j)
> {
>   ... coll1 finished; use j ...
> }
> 
> Best languages out there are at best ho-hum when it comes about 
> iterating through simultaneous streams. Most lose their elegant 
> iteration statement entirely and come with something that looks like an 
> old hooker early in the morning.
> 
> 
> Andrei

Isn't it possible to extend proposed syntax for something like suggested 
on D wish list:

http://all-technology.com/eigenpolls/dwishlist/index.php?it=42

---
In short: there is a proposition to add special cases in 'foreach' for 
first iterated element and last element. It could allow use of 'foreach' 
also for cases like

char[] arr = ["a", "b", "c"];
char[] res;
for(int i=0; i<arr.length-1; i++) {
	res~=arr[i] ~ ",";
}
if (arr.length>0) res~=arr[$-1];

into something like this (just raw proposition - syntax might by different):

foreach(e; arr) {
res~=e ~ ",";
}
last foreach(e) {
res~=e;
}

It seems that it would be logical consequence of proposed syntax... And 
would be very useful as above use case is quite popular IMHO.

Best Regards
Marcin Kuszczak



More information about the Digitalmars-d mailing list