Super-dee-duper D features

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Fri Feb 16 08:52:32 PST 2007


Bruno Medeiros wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> Bill Baxter wrote:
>>>
>>> You're of course welcome to your opinion, but multiple assignment 
>>> exists in many languages.  So you're saying they're all wrong to have 
>>> such a feature?
>>
>> No. It's good to have multiple assignments; it's annoying that Perl 
>> prevents the option of grouping initializers with the data if I so 
>> wanted:
>>
>> my $a = e1, $b = e2, $c = e3;
>>
>> I was just opining that
>>
>> foreach (a ; e1) (a2 ; e2) {}
>>
>> is clearer than:
>>
>> foreach (a ; b) (e1 ; e2) {}
>>
>>
>> Andrei
>>
> 
> Ah, but then would you agree that your simultaneous foreach proposal
> would only serve the purpose of grouping variables next to their data?
> I.e., it wouldn't help in terms of simplifying code complexity (as it
> might happen in other languages, like Perl which you mentioned in
> another post), since D can currently do this:
> 
>   foreach (x,y ; transpose_view(reverse_view(foo),bar)
>     //then why not this too?!
> 
> And your proposal would only serve to simplify the above to this:
> 
>   foreach (x ; reverse_view(foo)) (y ; bar)
>     //probably I could!
> 
> which IMO is negligible, and not worthy of adding such new syntax.

No, I would not agree.

We discussed at length in a couple of posts the advantages and
disadvantages of the foreach()() approach vs. library-based iterators.
In short, the foreach()() version is safer and potentially faster, but
more restricted.


Andrei



More information about the Digitalmars-d mailing list