300 – Lazy Delegate Evaluation

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 300 - Lazy Delegate Evaluation
Summary: Lazy Delegate Evaluation
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: rejects-valid
Depends on:
Blocks:
Reported: 2006年08月21日 00:50 UTC by Derek Parnell
Modified: 2014年02月15日 13:19 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Derek Parnell 2006年08月21日 00:50:52 UTC
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.
Comment 1 Walter Bright 2006年09月02日 19:45:22 UTC
Fixed 0.166


AltStyle によって変換されたページ (->オリジナル) /