Python's features, which requires D

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 21 18:52:28 PDT 2015


On Friday, 22 May 2015 at 01:17:17 UTC, weaselcat wrote:
> D doesn't have list comprehensions, so it's difficult to 
> directly port these.

I can not imagine how difficult it is to implement it in D, but 
I'm pretty sure that nested for loops to fill arrays (in D, you 
can call them differently, for example, force :)) will be very 
useful thing, because Python is a veryIt is often used.
Besides, I do not understand what could be the problem with 
nested loops in arrays, because std.algorithm.map works on the 
principle of nested loops. I think that the biggest problem in 
the implementation of this should not be. Excuse me if I'm wrong.

> off the top of my head, the last one can easily be done with 
> std.range.stride

import std.stdio, std.range;

void main()
{
     int[] a = [ 1, 2, 3, 4, 5, 6 ];

     writeln(stride(a, 2)); // [1, 3, 5] #odd #print(x[::2]) #OK
     // [2, 4, 6] #even #print(x[1::2]) #no equivalent in D

     auto x = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
     // [2, 6, 10] #print(x[1::4]) #no equivalent in D
}


More information about the Digitalmars-d-learn mailing list