www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 300] New: Lazy Delegate Evaluation

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

           Summary: Lazy Delegate Evaluation
           Product: D
           Version: 0.165
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: ddparnell bigpond.com


The example in the documentation fails to compile. We get the message...
   "voids have no value"

// TEST 1 
import std.stdio;

void dotimes(int count, void delegate() exp)
{
    for (int i = 0; i < count; i++)
       exp();
}

void foo1()
{
    int x = 0;
    dotimes(10, writef(x++));
}

bool scase(bool b, void delegate() dg)
{
    if (b)
    {   dg();
        return true;
    }
    return false;
}

void cond(bool delegate()[] cases ...)
{
    foreach (c; cases)
    {   if (c())
            break;
    }
}


void foo2()
{
    int v = 2;
    cond
    (
        scase(v == 1, writefln("it is 1")),
        scase(v == 2, writefln("it is 2")),
        scase(v == 3, writefln("it is 3")),
        scase(true,   writefln("it is the default"))
    );
}

void main()
{
    foo1();
    foo2();
}

// ------- code ends ----

I had to change "writef(...)" to "{writef();}" to get it to compile.


-- 
Aug 20 2006
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=300


bugzilla digitalmars.com changed:

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





Fixed 0.166


-- 
Sep 02 2006