Lazy list/range comprehensions
Peter Alexander
peter.alexander.au at gmail.com
Sun Oct 3 07:46:13 PDT 2010
== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> Since many years and many versions of Python the pythonic way to write that is to use a lazy iterable:
> def sumOfSquares (sequence):
> return sum(item * item for item in sequence)
> I have suggested few times a list/lazy comp syntax for D too, and I have tried to explain why it's a
good thing (it helps "chunking" in the mind of the programmer).
Out of curiosity, what syntax did you propose? I definitely agree that lazy range comprehensions would
be a Good Thing (tm).
That said, the current D way of writing it isn't all that different from Python:
return reduce!("a+b")(map!("a*a")(sequence), 0);
More information about the Digitalmars-d
mailing list