Thread overview
a newbie problem regarding splitter()
Apr 13, 2017
alex
Apr 13, 2017
Ali Çehreli
Apr 14, 2017
alex
April 13, 2017
Hello,

I've just started learning D, working my way through "The D Programming Language" by Andrei Alexandrescu. On page 8 there is:
import std.stdio, std.string;

void main(){
    uint[string] dictionary;
    foreach (line; stdin.byLine()){
        foreach (word; splitter(strip(line))){
	    if (word in dictionary) continue;
 	    auto newID = dictionary.length;
	    dictionary[word] = newID;
	    writeln(newID, '\t', word);
	}
    }
}

When i try to run it, i get that splitter is 'undefined'. I can't spot the error. Maybe a fresh pair of eyes will do it??

Thank you,
Alex
April 12, 2017
On 04/12/2017 11:33 PM, alex wrote:
> Hello,
>
> I've just started learning D, working my way through "The D Programming
> Language" by Andrei Alexandrescu.

Great book but a lot has changed in D since the book was written in 2010. Your issue is in the book's errata:

  http://erdani.com/tdpl/errata/

So, the following should work today:

import std.stdio, std.string;
import std.algorithm;

void main(){
    ulong[string] dictionary;
    foreach (line; stdin.byLine()){
        foreach (word; splitter(strip(line))){
            if (word in dictionary) continue;
            auto newID = dictionary.length;
            dictionary[word.idup] = newID;
            writeln(newID, '\t', word);
        }
    }
}

Ali

April 14, 2017
On Thursday, 13 April 2017 at 06:42:30 UTC, Ali Çehreli wrote:
> On 04/12/2017 11:33 PM, alex wrote:
> > Hello,
> >
> "The D Programming Language" by Andrei Alexandrescu.
>
> Great book but a lot has changed in D since the book was written in 2010. Your issue is in the book's errata:
>
>   http://erdani.com/tdpl/errata/
>
> So, the following should work today:
>

> Ali

Thank you Ali - very good.
Alex