www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - a newbie problem regarding splitter()

reply alex <alex.caracatsanis gmail.com> writes:
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
Apr 12
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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
Apr 12
parent alex <alex.caracatsanis gmail.com> writes:
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
Apr 13