[Issue 8879] New: std.range function should to be usable in a pure (and sometimes nothrow) situations
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Oct 23 15:32:42 PDT 2012
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 at puremagic.com
ReportedBy: bioinfornatics at gmail.com
--- Comment #0 from bioinfornatics <bioinfornatics at gmail.com> 2012-10-23 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: -------
More information about the Digitalmars-d-bugs
mailing list