problem with filter.

Knud Soerensen 4tuu4k002 at sneakemail.com
Mon Mar 18 00:27:20 PDT 2013


Hi

I am trying to generate 2 arrays which is modifications of clist.
But I am having some problems, how would you do it ?


#!/usr/bin/rdmd
import std.stdio;
import std.algorithm;

void main()
{

 bool[][][] clist=[[[true, true], [false, true]],[[true, false], [true,
true]],[[false, true], [true, true]]];

 auto x=0;
writeln(clist);

auto fpos=delegate bool(bool[][] a){return(a[x]!=[true,false]);};
auto fneg=delegate bool(bool[][] a){return(a[x]!=[false,true]);};
 writeln("pos:",map!(delegate (bool[][] a){a[x][0]=true; return
a;})(filter!(fpos)(clist)));
 writeln("neg:",map!(delegate (bool[][] a){a[x][1]=true; return
a;})(filter!(fneg)(clist)));


}
The code outputs:

[[[true, true], [false, true]], [[true, false], [true, true]], [[false,
true], [true, true]]]
pos:[[[true, true], [false, true]], [[true, true], [true, true]]]
neg:[[[true, true], [false, true]], [[true, true], [true, true]],[[true,
true], [true, true]]]

But I should be

[[[true, true], [false, true]], [[true, false], [true, true]], [[false,
true], [true, true]]]
pos:[[[true, true], [false, true]], [[true, true], [true, true]]]
neg:[[[true, true], [false, true]], [[true, true], [true, true]]]

Hope you can help.


More information about the Digitalmars-d-learn mailing list