Don't forget to bookmark the errata page: http://erdani.com/tdpl/errata/index.php?title=Main_Page ;)
On 12/16/10, Chris A <codexarca...@gmail.com> wrote: > Hmm... maybe my compiler was out of date. I downloaded DMD again and tried > your code, and it seems to build fine now. > > Sorry for the trouble then, thank you for setting me on the right path > Andrej. > > > Andrej Mitrovic Wrote: > >> This works fine for me: >> >> import std.stdio; >> import std.string; >> >> void main(string[] args) >> { >> uint[string] freqs; >> foreach(lines; stdin.byLine()) { >> foreach(word; split(strip(lines))) { >> ++freqs[word.idup]; >> } >> } >> foreach(key, value; freqs){ >> writefln("%6u\t%s", value, key); >> } >> getchar(); >> } >> >> Perhaps you missed an import >> >> On 12/16/10, Chris A <codexarca...@gmail.com> wrote: >> > Hey all, I'm going over some examples in Alexandrescu's book, but I >> > guess >> > something has changed in the language because the example isn't working >> > for >> > me. >> > >> > The simple example: >> > >> > void main(string[] args) >> > { >> > uint[string] freqs; >> > foreach(lines; stdin.byLine()) { >> > foreach(word; split(strip(lines))) { >> > ++freqs[word.idup]; >> > } >> > } >> > foreach(key, value; freqs){ >> > writefln("%6u\t%s", value, key); >> > } >> > din.getc(); >> > } >> > >> > >> > This throws an error during compile, like: >> > main.d(11): Error: no property 'ByLine' for type '_iobuf' >> > main.d(11): Error: function expected before (), not 1 of type int >> > main.d(11): Error: foreach: int is not an aggregate type >> > >> > So seemingly byLine is no longer an existing function on stdin. What is >> > the >> > current version of what this code is trying to do? >> > > >