Skip to content

Commit 634f9a3

Browse files
committed
Copy the average length example to the top
And also make it the default. The primary motivation is that we need to have a simple example for first time visitors.
1 parent 432eb1b commit 634f9a3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

index.dd

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,27 @@ $(DIVC intro, $(DIV, $(DIV,
3030
)
3131
$(DIVID your-code-here-default,
3232
$(RUNNABLE_EXAMPLE
33+
$(RUNNABLE_EXAMPLE_STDIN
34+
The D programming language
35+
Modern convenience.
36+
Modeling power.
37+
Native efficiency.)
38+
----
39+
// Compute average line length for stdin
40+
void main()
41+
{
42+
import std.range, std.stdio;
43+
44+
auto sum = 0.0;
45+
auto count = stdin.byLine
46+
.tee!(l => sum += l.length).walkLength;
47+
48+
writeln("Average line length: ",
49+
count ? sum / count : 0);
50+
}
51+
----
52+
)
53+
$(EXTRA_EXAMPLE
3354
$(RUNNABLE_EXAMPLE_STDIN 2.4 plus 2.4 equals 5 for sufficiently large values of 2.)
3455
----
3556
// Round floating point numbers

0 commit comments

Comments
 (0)