Super-dee-duper D features

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Tue Feb 13 17:52:11 PST 2007


Dave wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> Sean Kelly wrote:
>>> Andrei Alexandrescu (See Website For Email) wrote:
>>>> Frits van Bommel wrote:
>>>>> Andrei Alexandrescu (See Website For Email) wrote:
>>>>>> Bill Baxter wrote:
>>>>>>> Yeh, I don't get it either.  How would that help me implement 
>>>>>>> merge() from merge sort for instance?
>>>>>>
>>>>>> Merge bumps the iteration in both collections conditionally. The 
>>>>>> form above bumps the iteration in the two collections 
>>>>>> unconditionally, until one is finished; then it continues with the 
>>>>>> other until that is finished.
>>>>>
>>>>> In other words, it doesn't :(.
>>>>
>>>> A need for loops iterating over multiple collections depending on 
>>>> arbitrary conditions will always be there. The point of extending 
>>>> foreach is to address the often-encountered case when you want to 
>>>> iterate over multiple collections simultaneously (e.g.: copy a 
>>>> collection to another), just like foreach itself is addressing the 
>>>> particular but frequent case of iterating one collection in a linear 
>>>> manner.
>>>
>>> What about:
>>>
>>>     foreach (i ; coll1) (j ; coll2)
>>>     {
>>>         if( true )
>>>             continue i;
>>>     }
>>>
>>> ie. allow 'continue' to accept labels to specify which collection is 
>>> iterated.  A 'continue' without labels would iterate both.
>>
>> I think that's a great idea, except that "continue to label" has the 
>> same syntax: http://digitalmars.com/d/statement.html#ContinueStatement
>>
>> Andrei
> 
> How about using 'next' to keep it simple, so the compiler doesn't have 
> to create / check for 'i' and 'j' as lables with the same function scope:
> 
> i:  while(...)
>     {
>        foreach (i ; coll1) (j ; coll2)
>        {
>            if( true )
>                continue i;
>            if( i < j )
>                next i;
>        }
>     }
> ?

I think it's very desirable to add keywords only when there's an 
absolute must.

Andrei



More information about the Digitalmars-d mailing list