www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4804] New: Sequence example alternative

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

           Summary: Sequence example alternative
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



10:05:39 PDT ---
From: http://www.digitalmars.com/d/2.0/phobos/std_range.html#Sequence

// a[0] = 1, a[1] = 2, a[n] = a[0] + n * a[1]
auto odds = sequence!("a[0] + n * a[1]")(1, 2);

This has been reported in bug 3181 for not compiling.

But there's a workaround. If I use the "a.field[]" syntax instead of "a[0]",
then the original example in the documentation works:

auto odds = sequence!("a.field[0] + n * a.field[1]")(1, 2);


There are also some weird bugs in the sequence unittest in range.d. Apparently
you can't call both Sequence and sequence in the same code. That code is
commented out with "  BUG", but there's no bug number so I guess it wasn't
reported yet, or maybe someone is already working on it.. 
But anyway, here's the gist of it:

import std.range;
import std.typecons;

void main()
{
    alias Sequence!("a.field[0] + n * a.field[1]", Tuple!(int, int)) Gen;
    auto y = sequence!("a.field[0] + n * a.field[1]")(0, 4);
}

C:\DMD\dmd2\windows\bin\..\..\src\phobos\std\range.d(2459): Error
: this for _cache needs to be type Sequence not type Sequence!("a
.field[0] + n * a.field[1]",Tuple!(int,int))

If you uncomment either line, the example compiles.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 03 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4804


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

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



11:48:37 PST ---
Both of these have been fixed in a recent release.

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