[Issue 8882] New: map, filter, iota and zip in pure (and nothrow) functions
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Oct 23 16:43:45 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8882
Summary: map, filter, iota and zip in pure (and nothrow)
functions
Product: D
Version: D2
Platform: x86
OS/Version: Windows
Status: NEW
Keywords: rejects-valid
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2012-10-23 16:43:44 PDT ---
This is not an enhancement request, I think of it as a bug report. This is a
spinoff of Issue 8878
To make functional programming in D a better experience, the following
functions should be usable in a pure (and possibly nothrow) context:
import std.algorithm: map, filter;
import std.range: iota, zip;
void main() pure nothrow {
auto m = map!q{a * a}([1, 2, 3]);
auto f = filter!q{ a > 1 }([1, 2, 3]);
auto i = iota(1, 10, 2);
auto z = zip([1, 2, 3], [10, 20, 30]);
}
DMD 2.061alpha gives:
test.d(4): Error: pure function 'main' cannot call impure function 'map'
test.d(5): Error: pure function 'main' cannot call impure function 'filter'
test.d(6): Error: pure function 'main' cannot call impure function 'iota'
test.d(7): Error: pure function 'main' cannot call impure function 'zip'
test.d(4): Error: map is not nothrow
test.d(5): Error: filter is not nothrow
test.d(6): Error: iota is not nothrow
test.d(7): Error: zip is not nothrow
test.d(3): Error: function D main 'main' is nothrow yet may throw
Note: zip() accepts a StoppingPolicy, so this can't be nothrow:
import std.range: zip, StoppingPolicy;
void main() pure {
auto z = zip(StoppingPolicy.requireSameLength, [1,2,3], [10,20]);
foreach (t; z) {} // throws
}
--
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