Skip to content

Commit e0624ce

Browse files
committed
Fix AA word count example
Add Examples heading otherwise they're listed under Properties. Make example get compiled. Add missing import.
1 parent 6a4cda2 commit e0624ce

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

spec/hash-map.dd

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,20 +468,23 @@ $(P Properties for associative arrays are:)
468468
else evaluates the $(D create) delegate and adds it to the associative array))
469469
)
470470

471-
$(HR)
471+
$(H2 $(LNAME2 examples, Examples))
472+
472473
$(H3 $(LNAME2 aa_example, Associative Array Example: word count))
473474

474475
$(P Let's consider the file is ASCII encoded with LF EOL.
475476
In general case we should use $(I dchar c) for iteration
476477
over code points and functions from $(LINK2 $(ROOT_DIR)phobos/std_uni.html,std.uni).
477478
)
478479

480+
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
479481
---------
482+
import std.algorithm : sort;
480483
import std.file; // D file I/O
481484
import std.stdio;
482485
import std.ascii;
483486

484-
void main (string[] args)
487+
void main(string[] args)
485488
{
486489
ulong totalWords, totalLines, totalChars;
487490
ulong[string] dictionary;
@@ -491,7 +494,7 @@ $(H3 $(LNAME2 aa_example, Associative Array Example: word count))
491494
{
492495
ulong wordCount, lineCount, charCount;
493496

494-
foreach(line; File(arg).byLine())
497+
foreach (line; File(arg).byLine())
495498
{
496499
bool inWord;
497500
size_t wordStart;
@@ -549,6 +552,7 @@ $(H3 $(LNAME2 aa_example, Associative Array Example: word count))
549552
}
550553
}
551554
---------
555+
)
552556

553557
$(H3 $(LNAME2 aa_example_iteration, Associative Array Example: counting Tuples))
554558

0 commit comments

Comments
 (0)