Lutger:
> 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?

It's not terrible, but it's far from being nice. Strings are sharp and rough 
tools, when used for such purposes.
Map and filter of Phobos2 are lazy only, so if you need an array you have to 
add another function call (that's named array() in my dlibs, I don't remember 
the Phobos2 name).


> (the range function is fictional, I forgot if and which one exists in 
> phobos)

In Phobos2 it's named iota (from APL, maybe), it doesn't require the 
exclamation mark (bang, !) (but it's not smart enough yet to accept just one 
argument, and default the first one to zero).

Bye,
bearophile

Reply via email to