Super-dee-duper D features
Andrei Alexandrescu (See Website For Email)
SeeWebsiteForEmail at erdani.org
Tue Feb 13 17:50:32 PST 2007
renoX wrote:
> Andrei Alexandrescu (See Website For Email) a écrit :
>> 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.
>
> At first, I really didn't like the 'continue foreach', then afterwards I
> got used to it, I wonder if this is really such a requested feature
> though, what's wrong with the good old 'for' or 'while' for the complex
> case?
Absolutely nothing's wrong. The same argument, however, could be
formulated to render foreach redundant. We have for, don't we.
The thing is foreach is terse and elegant and has a functional flavor
that gives it safety and power that for doesn't have. It's only natural
to ask oneself why all of these advantages must go away in a blink just
because you want to iterate two things simultaneously.
Andrei
More information about the Digitalmars-d
mailing list