www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8879] New: std.range function should to be usable in a pure (and sometimes nothrow) situations

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8879

           Summary: std.range function should to be usable in a pure (and
                    sometimes nothrow) situations
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bioinfornatics gmail.com



15:32:40 PDT ---
Code below fail when using pure with both dmd/ldc  dmdfe 2.060

___________________________________________
This gives:
/home/c135/c554.d(6): Error: pure function 'square' cannot call impure function
'zip'
/home/c135/c554.d(6): Error: pure function 'square' cannot call impure function
'empty'
/home/c135/c554.d(6): Error: pure function 'square' cannot call impure function
'popFront'
/home/c135/c554.d(6): Error: pure function 'square' cannot call impure function
'front'
---------
import std.range;
import std.stdio;

pure uint square( in int[] x, in int[] y ){
    uint result = 0;
    foreach( item; zip( x, y ) )
        result += item[0] * item[1];
    return result;
}

int main(){
    int[3] a = [0,1,2];
    int[3] b = [1,2,3];
    writefln( "Square of %s with %s give %u", a, b, square( a, b ) );
    return 0;
}
___________________________________________


Bearophile code
___________________________________________
This gives:
test.d(3): Error: pure function 'main' cannot call impure function 'iota'
---------
import std.range: iota;
void main() pure {
    iota(10);
}
___________________________________________

This gives:
test.d(4): Error: pure function 'main' cannot call impure function 'map'
test.d(4): Error: map is not nothrow
test.d(2): Error: function D main 'main' is nothrow yet may throw
---------
import std.algorithm: map;
void main() pure nothrow {
    int[] data = [1, 2, 3];
    auto r = map!q{a * a}(data);
}
___________________________________________

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 23 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8879


bioinfornatics <bioinfornatics gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



11:16:24 PDT ---
*** This issue has been marked as a duplicate of issue 8882 ***

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