Peter Alexander wrote:
> == Quote from Jimmy Cao (jcao...@gmail.com)'s article
>> The Python version:
>> sum(item * item for item in sequence)
>> can be translated to English as:
>> "Sum of (item * item) foreach item in sequence"
>> While the D version:
>> reduce!("a+b")(map!("a*a")(sequence), 0);
>> looks to me like:
>> Reduce! a plus b map! a times a (sequence) (and a random 0 here).
> 
> If you write it as:
> 
> auto sum(Range)(Range r) { return reduce!("a+b")(r, 0); }
> alias unaryFun("a*a") square;
> alias map!(square) squares;
> 
> return sum(squares(sequence));
> 
> then it looks better than Python :-)
> 
> Or can we only judge a language by what's in its standard library?
> 
        Given that you can do the same but shorter in Python, then I'd say
yes. Especially since even when choosing an obscure way to define
"squares" it's still more readable...

squares = lambda s: type (s) (x*x for x in seq)

return sum (squares (sequence))

                Jerome
-- 
mailto:jeber...@free.fr
http://jeberger.free.fr
Jabber: jeber...@jabber.fr

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to