newbie question: can D do this?
clk at clksoft.com
Thu Dec 22 07:45:17 PST 2011
I don't understand the example below to simulate the list comprehension
syntax. Are input1, input2 and input3 ranges? Where is the comp
auto lc = comp!("tuple(a,b,c)", "a*a+b*b == c*c&& a<b")(input1,input2, input3);
> Message: 2
> Date: Tue, 20 Dec 2011 21:45:26 +0100
> From: Philippe Sigaud<philippe.sigaud at gmail.com>
> To: "digitalmars.D.learn"<digitalmars-d-learn at puremagic.com>
> Subject: Re: newbie question: Can D do this?
> <CAOA6Bi6BaYm1T3PhvWY9mBRPsedK_dDjWYr-7yDO5cOV2ddiTw at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
> On Mon, Dec 19, 2011 at 17:17, clk<clk at clksoft.com> wrote:
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Digitalmars-d-learn