Error in 'The D Programming Language' (2010)?
asdfa via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jan 11 16:28:46 PST 2016
I have copied more or less verbatim an example from The D
Programming Language, under 1.4.3 Counting Frequencies. Lambda
Functions
This is the code
import std.stdio,
std.string;
void main()
{
uint[string] freqs;
// Compute counts
foreach (line; stdin.byLine())
{
foreach (word; split(strip(line)))
{
++freqs[word.idup];
}
}
// Print counts
string[] words = freqs.keys;
sort!((a, b) { return freqs[a] > freqs[b]; })(words); // won't
compile ????
foreach (word; words)
{
writefln("%6u\t%s", freqs[word], words);
}
}
Both DMD and GDC complain, saying
Error: template instance sort!((a, b)
{
return freqs[a] > freqs[b];
}
) template 'sort' is not defined
Have I made a mistake, or has the D syntax perhaps changed since
the book was published?
I don't understand this functional voodoo stuff, so I don't have
the faintest clue how to fix it myself
Anyone know how to fix this?
More information about the Digitalmars-d-learn
mailing list