Thread overview
[Issue 9740] New: strange interaction between map and filter
Mar 17, 2013
Knud
Mar 17, 2013
Maxim Fomin
Mar 17, 2013
Knud
March 17, 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@puremagic.com
        ReportedBy: knud@all-technology.com


--- Comment #0 from Knud <knud@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: -------
March 17, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9740


Maxim Fomin <maxim@maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim@maxim-fomin.ru
         OS/Version|Linux                       |All


--- Comment #1 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-03-17 01:39:12 PDT ---
What exactly is wrong?

Removed OS specific since same happens on windows.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 17, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9740



--- Comment #2 from Knud <knud@all-technology.com> 2013-03-17 01:46:20 PDT ---
(In reply to comment #1)
> What exactly is wrong?
The second filter don't work, but it should.

> 
> Removed OS specific since same happens on windows.

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