July 27, 2009 Re: Reddit: why aren't people using D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu wrote:
> Lutger wrote:
>> python:
>> (x * x for x in xrange(10, 20) if x & 1)
>>
>> D as of now:
>> map!("a * a")( filter!("a & 1")( range!(10,20) ) )
>>
>> D with extension methods:
>> range!(10,20).filter!("a & 1").map!("a * a")
>>
>> Not too bad right?
>>
>> (the range function is fictional, I forgot if and which one exists in
>> phobos)
>
> (It's called iota.)
>
> Andrei
Oh yes, I remember being freaked out reading about the APL after that one:
(~R∊R∘.×R)/R←1↓⍳R
(this finds all prime numbers from 1 to R in the APL)
|
July 27, 2009 Re: Reddit: why aren't people using D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lutger | Lutger: > Oh yes, I remember being freaked out reading about the APL after that one: > (~R∊R∘.×R)/Râ†1↓â³R > (this finds all prime numbers from 1 to R in the APL) I can't read that APL code, and Python code that does the same is more than twice longer (and it may also be slower): >>> n = 20 >>> [x for x in xrange(2,n) if all(x % i for i in xrange(2,x))] [2, 3, 5, 7, 11, 13, 17, 19] Bye, bearophile |
Copyright © 1999-2021 by the D Language Foundation