newbie question: Can D do this?
Philippe Sigaud
philippe.sigaud at gmail.com
Tue Dec 20 12:45:26 PST 2011
On Mon, Dec 19, 2011 at 17:17, clk <clk at clksoft.com> wrote:
> 2) D doesn't seem to support the list comprehension syntax available in
> python and javascript. Is this correct?
>
> [f(x) for x in list if condition]
Correct. As other have said, it's doable by combining std functions.
As fas as I know, we do not have a cartesian product range, to iterate
on all combinations of two or more ranges.
[f(x,y) for x in list1 for y in list2 if condition]
I gave it a try a few years ago and could get something like this:
auto lc = comp!("tuple(a,b,c)", "a*a+b*b == c*c && a<b")(input1,
input2, input3);
-> mapper, condition,
input ranges, as many as you wish
But at the time I couldn't find a way to do bindings, that is:
[f(x,y) for x in [0..10] for y in [0..x]]
-> the range iterated by y depends on x.
If anyone has an idea, I'm game.
Philippe
More information about the Digitalmars-d-learn
mailing list