List comprehensions in D?

Rémy Mouëza ray.jay.ay.mouezaatgmaildotcom
Sun Jun 25 16:10:55 PDT 2006


In article <e7mg88$1mh3$1 at digitaldaemon.com>, David Medlock says...
>
>David Medlock wrote:
>> My meager attempts to clone some list functionality in Python:
>> 
>> r = [ y for y in array if y > 10 ];
><snip>
>> Pretty cool, IMO.
>> -DavidM
>
>in addition,
>
>If you consider that arrays are just machine-optimized versions of 
>maps(or graphs) with the allowed index as integers between 0 and N,
>then passing a predicate function on those indexes makes some sense.
>
>for containers: (depending on your view of the syntax)
>
>T[]  opIndex( bool delegate(T) dg ) { return items.where( dg ); }
>T[]  opIndexAssign( void delegate( inout T) dg ){ items.update( dg ); }
>
>x = vector[ (int t){return t>5;} ]; // subset of vector
>vector[] = (inout int x) { x += 100; } ; // update all members of vector
>
>And of course extending to opSlice/opSliceAssign....
>
>-DavidM

Wonderfull !!!
And simply powerfull too !!!

D is looking more and more like a strongly typed Python like language with
braces. Compiled languages can also support high level programming ( if well
designed, but D is indeed ).






More information about the Digitalmars-d mailing list