Super-dee-duper D features

kris foo at bar.com
Tue Feb 13 15:38:47 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;
>        }
>     }
> ?


No offence to anyone, but the above and the other so far are *way* too 
complex for such an operation. They are not simple to follow at all, and 
could easily be the source of tricky bugs.

Perhaps it would be worthwhile waiting until we get some useful form or 
Iterator before adding this type of complex syntax?

(InterleavingIterator encapsulates the trickiness, such that it is 
trivial to use, and works every time)

- Kris



More information about the Digitalmars-d mailing list