Thread overview
[Issue 3123] New: std.algorithm.zip fails on 'lazy' ranges
Jul 01, 2009
k-foley@onu.edu
Oct 25, 2009
David Simcha
Oct 26, 2009
Kyle Foley
Oct 26, 2009
Kyle Foley
Oct 26, 2009
Kyle Foley
Aug 16, 2010
David Simcha
July 01, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3123

           Summary: std.algorithm.zip fails on 'lazy' ranges
           Product: D
           Version: 2.030
          Platform: Other
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: k-foley@onu.edu


By 'lazy' range, I mean what iota, map, take, etc. return.  I don't know the correct term for these types of ranges.
----

auto a = [1, 2, 3, 4, 5][];
auto b = [2, 4, 6, 8, 10][];

// this compiles and works fine
foreach ( e; zip(a, b) ) writeln( "(", e.at!0, ", ", e.at!1, ")" );

// the following do not
foreach ( e; zip(a, iota(0, 6)) ) writeln( "(", e.at!0, ", ", e.at!1, ")" );

foreach ( e; zip(a, take(5, repeat(42))) ) writeln( "(", e.at!0, ", ", e.at!1,
")" );

foreach ( e; zip(a, map!(`a*a`)(a)) ) writeln( "(", e.at!0, ", ", e.at!1, ")"
);

----
Here is the compilation error:

C:\d\dmd.2.030\dmd\windows\bin\..\..\src\phobos\std\range.d(1734): Error:
cannot
 implicitly convert expression (&this.ranges._field_field_1.front) of type int
d
elegate() to int*

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 25, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3123


David Simcha <dsimcha@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dsimcha@yahoo.com


--- Comment #1 from David Simcha <dsimcha@yahoo.com> 2009-10-25 15:30:37 PDT ---
The problem looks to be a question of whether range.front is an lvalue or not. When range.front is an lvalue, DMD interprets &range.front as taking the address of the front element of the range.  When range.front is not an lvalue, DMD interprets &range.front as taking the address of the member function front() of range.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 26, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3123



--- Comment #2 from Kyle Foley <k-foley@onu.edu> 2009-10-25 21:08:42 PDT ---
Created an attachment (id=481)
Zip fixes

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 26, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3123



--- Comment #3 from Kyle Foley <k-foley@onu.edu> 2009-10-25 21:10:50 PDT ---
(In reply to comment #1)
> The problem looks to be a question of whether range.front is an lvalue or not. When range.front is an lvalue, DMD interprets &range.front as taking the address of the front element of the range.  When range.front is not an lvalue, DMD interprets &range.front as taking the address of the member function front() of range.

The problem is that Proxy tries to store a pointer to the fronts of each range.
 In the case of these 'lazy' ranges, the pointer makes no sense.  I have
uploaded a new version of Zip which I think solves this problem.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 26, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3123



--- Comment #4 from Kyle Foley <k-foley@onu.edu> 2009-10-25 21:13:39 PDT ---
(In reply to comment #2)
> Created an attachment (id=481) [details]
> Zip fixes

I changed Proxy to store by reference for ranges supporting reference return types and by value otherwise.  I also changed Zip to only support back and popBack when all ranges are bidirectional.  And I also changed Proxy.at to return by reference.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 26, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3123


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: -------
August 16, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3123


David Simcha <dsimcha@yahoo.com> changed:

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


--- Comment #5 from David Simcha <dsimcha@yahoo.com> 2010-08-15 19:55:27 PDT ---
Fixed SVN.

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