Python's features, which requires D

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 11 07:18:02 PDT 2015


On Saturday, 23 May 2015 at 10:58:33 UTC, Kagamin wrote:
> On Saturday, 23 May 2015 at 02:36:14 UTC, Dennis Ritchie wrote:
>> For example, the code in Python looks quite natural:
>>
>> a = [[int(j) for j in input().split()] for i in range(n)]
>>
>> About D-code, I can not say:
>>
>>>auto a = stdin
>>>         .byLine
>>>         .map!(l => l.splitter.map!(to!int).array)
>>>         .take(n);
>
> Well, list comprehension is built into language in python (and 
> not in D), such level of support is definitely more streamlined.

Yes, but D is also possible to create a strong inclusion of list 
comprehensions. Here's the proof:
https://github.com/pplantinga/delight

> Probably the coolest feature in Delight is list comprehensions. 
> Delight uses functions in std.algorithm to generate an iterable 
> range. The syntax is similar to Python's. See the last two 
> lines of the code above for an example.

print { i * 2 for i in 0 .. 5 where i ^ 2 less than 5 }
# prints [0, 2, 4]


More information about the Digitalmars-d-learn mailing list