[Issue 8882] map, filter, iota and zip in pure (and nothrow) functions

2017-08-30 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=8882

--- Comment #10 from ZombineDev  ---
(In reply to RazvanN from comment #9)
> (In reply to ZombineDev from comment #8)
> > While, the OP code compiles, zip is not yet nothrow. See:
> > 
> > ```
> > import std.algorithm: map, filter;
> > import std.range: iota, zip, array;
> > import std.typecons : tuple;
> > 
> > auto get() 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]);
> > return tuple(m.array, f.array, i.array, z.array);
> > }
> > 
> > void main()
> > {
> > import std.stdio;
> > writeln(get());
> > }
> > ```
> > 
> > test.d(11): Error: function std.array.array!(Zip!(int[], int[])).array is
> > not nothrow
> > test.d(4): Error: nothrow function test.get may throw
> 
> There already is issue 11466 [1] which addresses problem, so I suggest we
> close this and fix that one. 
> 
> [1] https://issues.dlang.org/show_bug.cgi?id=11466

I missed that one, so yes, we should close this one, thanks.

--


[Issue 8882] map, filter, iota and zip in pure (and nothrow) functions

2017-08-30 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=8882

RazvanN  changed:

   What|Removed |Added

 Status|REOPENED|RESOLVED
 Resolution|--- |FIXED

--- Comment #9 from RazvanN  ---
(In reply to ZombineDev from comment #8)
> While, the OP code compiles, zip is not yet nothrow. See:
> 
> ```
> import std.algorithm: map, filter;
> import std.range: iota, zip, array;
> import std.typecons : tuple;
> 
> auto get() 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]);
> return tuple(m.array, f.array, i.array, z.array);
> }
> 
> void main()
> {
> import std.stdio;
> writeln(get());
> }
> ```
> 
> test.d(11): Error: function std.array.array!(Zip!(int[], int[])).array is
> not nothrow
> test.d(4): Error: nothrow function test.get may throw

There already is issue 11466 [1] which addresses problem, so I suggest we close
this and fix that one. 

[1] https://issues.dlang.org/show_bug.cgi?id=11466

--


[Issue 8882] map, filter, iota and zip in pure (and nothrow) functions

2017-08-29 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=8882

ZombineDev  changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
 CC||petar.p.ki...@gmail.com
 Resolution|FIXED   |---

--- Comment #8 from ZombineDev  ---
While, the OP code compiles, zip is not yet nothrow. See:

```
import std.algorithm: map, filter;
import std.range: iota, zip, array;
import std.typecons : tuple;

auto get() 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]);
return tuple(m.array, f.array, i.array, z.array);
}

void main()
{
import std.stdio;
writeln(get());
}
```

test.d(11): Error: function std.array.array!(Zip!(int[], int[])).array is not
nothrow
test.d(4): Error: nothrow function test.get may throw

--


[Issue 8882] map, filter, iota and zip in pure (and nothrow) functions

2017-08-28 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=8882

RazvanN  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||razvan.nitu1...@gmail.com
 Resolution|--- |FIXED

--- Comment #7 from RazvanN  ---
The code in the original bug report now compiles. Closing this as fixed.

--


[Issue 8882] map, filter, iota and zip in pure (and nothrow) functions

2014-01-16 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=8882


monarchdo...@gmail.com changed:

   What|Removed |Added

 CC||monarchdo...@gmail.com


--- Comment #4 from monarchdo...@gmail.com 2014-01-16 11:58:06 PST ---
(In reply to comment #2)
 The situation has now improved:

Yeah, thanks Kenji!

 zip can throw because of StoppingPolicy.requireSameLength, and iota(x,y,z)
 throws when z can be 0. iota(x) and iota(x,y) are nothrow.
 
 I think the problem with zip() can be solved introducing an api change, or
 adding a new zip overload that takes StoppingPolicy as first template 
 argument.

Yes, having a run-time condition is awful IMO. It should always be know compile
time. It can also create subtle issues for things such as hasSlicing, which
only works for certain stopping tipes.

 Fixing iota(x,y,z) is less easy. z is often a value known at compile time, so
 in theory a new version of iota!z(x, y) can be nothrow at run-time.
 
 even iota(x,y) is not nothrow for floating point arguments:
 
 
 import std.range: iota;
 void main() nothrow {
 iota(1.0, 2.0);
 }
 
 test.d(3): Error: 'std.range.iota!(double, double).iota' is not nothrow
 test.d(2): Error: function 'D main' is nothrow yet may throw

Bah, I think illegal input should Error. Problem solved.

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


[Issue 8882] map, filter, iota and zip in pure (and nothrow) functions

2014-01-16 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=8882



--- Comment #6 from monarchdo...@gmail.com 2014-01-16 13:53:55 PST ---
(In reply to comment #5)
 (In reply to comment #4)
 
  Bah, I think illegal input should Error. Problem solved.
 
 Changing an exception - error changes the API of iota()

Yes, but I think it's a valid change.

 , but in this case I
 think there's no need to change the API. iota(1.0, 2.0); can be nothrow with
 small changes in the Phobos code, keeping the same API.

But that's a special case. What about iota(1.0, 2.0, 0.1) ?

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


[Issue 8882] map, filter, iota and zip in pure (and nothrow) functions

2014-01-16 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=8882



--- Comment #5 from bearophile_h...@eml.cc 2014-01-16 13:50:42 PST ---
(In reply to comment #4)

 Bah, I think illegal input should Error. Problem solved.

Changing an exception - error changes the API of iota(), but in this case I
think there's no need to change the API. iota(1.0, 2.0); can be nothrow with
small changes in the Phobos code, keeping the same API.

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


[Issue 8882] map, filter, iota and zip in pure (and nothrow) functions

2014-01-14 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=8882



--- Comment #2 from bearophile_h...@eml.cc 2014-01-14 03:16:34 PST ---
The situation has now improved:


import std.algorithm: map, filter;
import std.range: iota, zip;
void main() pure nothrow {
foreach (_; map!q{a * a}([1, 2, 3])) {}
foreach (_; filter!q{ a  1 }([1, 2, 3])) {}
foreach (_; iota(1, 10, 2)) {}
foreach (_; zip([1, 2, 3], [10, 20, 30])) {}
}


test.d(6): Error: 'std.range.iota!(int, int, int).iota' is not nothrow
test.d(7): Error: 'std.range.Zip!(int[], int[]).Zip.empty' is not nothrow
test.d(7): Error: 'std.range.Zip!(int[], int[]).Zip.popFront' is not nothrow
test.d(3): Error: function 'D main' is nothrow yet may throw


zip can throw because of StoppingPolicy.requireSameLength, and iota(x,y,z)
throws when z can be 0. iota(x) and iota(x,y) are nothrow.

I think the problem with zip() can be solved introducing an api change, or
adding a new zip overload that takes StoppingPolicy as first template argument.

Fixing iota(x,y,z) is less easy. z is often a value known at compile time, so
in theory a new version of iota!z(x, y) can be nothrow at run-time.

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


[Issue 8882] map, filter, iota and zip in pure (and nothrow) functions

2014-01-14 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=8882



--- Comment #3 from bearophile_h...@eml.cc 2014-01-14 13:22:18 PST ---
(In reply to comment #2)

 zip can throw because of StoppingPolicy.requireSameLength, and iota(x,y,z)
 throws when z can be 0. iota(x) and iota(x,y) are nothrow.

even iota(x,y) is not nothrow for floating point arguments:


import std.range: iota;
void main() nothrow {
iota(1.0, 2.0);
}

test.d(3): Error: 'std.range.iota!(double, double).iota' is not nothrow
test.d(2): Error: function 'D main' is nothrow yet may throw

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


[Issue 8882] map, filter, iota and zip in pure (and nothrow) functions

2012-10-24 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=8882


bioinfornatics bioinfornat...@gmail.com changed:

   What|Removed |Added

 CC||bioinfornat...@gmail.com


--- Comment #1 from bioinfornatics bioinfornat...@gmail.com 2012-10-24 
11:16:25 PDT ---
*** Issue 8879 has been marked as a duplicate of this issue. ***

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