The Many Faces of D - slides

Simen kjaeraas simen.kjaras at gmail.com
Sun Oct 3 16:40:00 PDT 2010


Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:

>> assert( equal( ( list!"2 * a" | [1,2,3,4,5] & where!"a & 1" ), [2,6,10]
>> ) );
>> assert( equal( ( list!"2 * a" | [1,2,3] ), [2,4,6] ) );
>> }
>
> I wonder to what extent this improves
>
> assert(equal(map!"2 * a"(filter!"a & 1"([1,2,3,4,5])), [2,6,10]));
>
> One thing that's nicer with comprehensions is that you save a bit on  
> nested parens.

In my opinion, it improves it by looking more like math language (with
which I am familiar, but this is of course a subjective measure):

( list!"2 * a" | [ 1, 2, 3, 4, 5 ] & where!"a & 1" )
vs
{ 2 * a | a ∈ [ 1, 2, 3, 4, 5 ], a & 1 != 0 }

I also feel it is less cluttered and 'flows' better than your example,
but this may very well be the same issue as above.

-- 
Simen


More information about the Digitalmars-d mailing list