[Issue 300] New: Lazy Delegate Evaluation
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Aug 20 22:51:00 PDT 2006
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 at digitalmars.com
ReportedBy: ddparnell at 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.
--
More information about the Digitalmars-d-bugs
mailing list