[Issue 9740] New: strange interaction between map and filter

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Mar 17 01:16:26 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9740

           Summary: strange interaction between map and filter
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: knud at all-technology.com


--- Comment #0 from Knud <knud at all-technology.com> 2013-03-17 01:16:24 PDT ---
#!/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("neg:",map!(delegate (bool[][] a){a[x][1]=true; return
a;})(filter!(fneg)(clist)));   
 writeln("pos:",map!(delegate (bool[][] a){a[x][0]=true; return
a;})(filter!(fpos)(clist)));    

}

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

if you change the order of the writeln you get:[[[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]]]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list