| Thread overview | |||||
|---|---|---|---|---|---|
|
April 13, 2017 a newbie problem regarding splitter() | ||||
|---|---|---|---|---|
| ||||
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 Re: a newbie problem regarding splitter() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to alex | 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 Re: a newbie problem regarding splitter() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 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 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply