digitalmars.D.learn - Problems with stdio.byLine() in D Book
- Chris A (20/20) Dec 16 2010 Hey all, I'm going over some examples in Alexandrescu's book, but I gues...
- Andrej Mitrovic (18/41) Dec 16 2010 This works fine for me:
- Chris A (3/54) Dec 16 2010 Hmm... maybe my compiler was out of date. I downloaded DMD again and tr...
- Andrej Mitrovic (3/62) Dec 16 2010 Don't forget to bookmark the errata page:
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?
Dec 16 2010
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 <CodexArcanum 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?
Dec 16 2010
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 <CodexArcanum 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?
Dec 16 2010
Don't forget to bookmark the errata page: http://erdani.com/tdpl/errata/index.php?title=Main_Page ;) On 12/16/10, Chris A <CodexArcanum 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 <CodexArcanum 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?
Dec 16 2010