digitalmars.D.learn - a newbie problem regarding splitter()
- alex (19/19) Apr 12 2017 Hello,
- =?UTF-8?Q?Ali_=c3=87ehreli?= (19/22) Apr 12 2017 Great book but a lot has changed in D since the book was written in
- alex (3/12) Apr 13 2017 Thank you Ali - very good.
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 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
Apr 12 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:AliThank you Ali - very good. Alex
Apr 13 2017