www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4729] New: std.algorithm: atrange iota behaviour

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

           Summary: std.algorithm: atrange iota behaviour
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Optlink
        AssignedTo: nobody puremagic.com
        ReportedBy: necroment gmail.com



import std.stdio, std.algorithm, std.range;

void main() {
    filter!((int n) { write(n, ' '); return 0; })(iota(1, 10));
    //writes: 1 2 3 4 5 6 7 8 9

    writeln();

    reduce!"0"(
        filter!((int n) { write(n, ' '); return 1; })(iota(1, 10))
    ); //writes: 1 2 3 4 5 6 7 8 9

    writeln();

    reduce!"0"(
        filter!((int n) { write(n, ' '); return 0; })(iota(1, 10))
    ); //Never stops writing numbers
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 26 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4729


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc
            Summary|std.algorithm: atrange iota |std.algorithm: strange iota
                   |behaviour                   |behaviour



It seems a iota() problem.


import std.algorithm: reduce, filter;
import std.range: iota;
void main() {
    reduce!"0"(filter!((int a){ return false; })(iota(1)));
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 26 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4729




This bug was introduced in 2.048, as is 2.047 iota stops but fails shortly
after:
src/phobos/std/algorithm.d(279): Enforcement failed

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 26 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4729


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4729


Brad Anderson <eco gnuk.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eco gnuk.net



2.057 seems to handle this situation (trying to reduce an empty range but not
offering a seed) by throwing an appropriate exception:

object.Exception C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(662):
Cannot reduce an empty range w/o an explicit seed value.

I believe this should be closed. Also, not sure why this is set as an optlink
issue.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4729


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh quickfur.ath.cx



In latest git head, throws an exception. Is this acceptable (should the bug be
closed)?

Or is it better to have reduce return (ElementType!R).init?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 03 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4729





 In latest git head, throws an exception. Is this acceptable (should the bug be
 closed)?
 
 Or is it better to have reduce return (ElementType!R).init?
The reduce of Python returns the start value:
 reduce(lambda a,b: a * b, [], 0)
0 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 04 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4729




The problem here is that no start value is given.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 04 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4729





 The problem here is that no start value is given.
In this case Python raises an error. I think this is acceptable:
 reduce(lambda a,b: a * b, [])
Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: reduce() of empty sequence with no initial value -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 04 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4729




In that case, we should probably close the bug, since the latest Phobos throws
an exception upon calling reduce() with an empty range and no start value.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 04 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4729


Andrei Alexandrescu <andrei erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED



PDT ---
Looks good: exception thrown if no seed, seed returned if it exists.

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