Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 16, 2010 Problems with stdio.byLine() in D Book | ||||
---|---|---|---|---|
| ||||
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? |
December 16, 2010 Re: Problems with stdio.byLine() in D Book | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris A | 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?
>
|
December 16, 2010 Re: Problems with stdio.byLine() in D Book | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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?
> >
|
December 16, 2010 Re: Problems with stdio.byLine() in D Book | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris A | 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? >> > > > |
Copyright © 1999-2021 by the D Language Foundation