February 16, 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
February 16, 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?!

Oh, I wasn't thinking D could actually do this already.  Is a generic transpose_view possible using a variadic opApply?  I don't think so but maybe I'm wrong.   You'd need
   int opApply( int delegate(Args...) body ) {
      . . .
   }

Does that work?

--bb
February 18, 2007
Bill Baxter wrote:
> 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?!
> 
> Oh, I wasn't thinking D could actually do this already.  Is a generic transpose_view possible using a variadic opApply?  I don't think so but maybe I'm wrong.   You'd need
>    int opApply( int delegate(Args...) body ) {
>       . . .
>    }
> 
> Does that work?
> 
> --bb

Oops, my mistake, that "since D can currently do this" is wrong.
It's not implementable, you need an actual iterator concept to do that, but so does Andrei's simultaneous foreach (news://news.digitalmars.com:119/45D48352.50802@erdani.org), so those examples are comparable.

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
7 8 9 10 11 12 13 14 15 16 17
Next ›   Last »