On 22/10/2016 6:25 PM, Mark wrote:
Hello, Im a 3rd year Comp Sci student in Edmonton Alberta, Canada.
Ive learned how to use C, and dabbled in C++ in school. Im also in a Oop
course using Java.
I picked up the book The D Programming Language by Alexrei Alexandrescu
a few years ago.
Lately Im really wanting to get into D, as It seems like a better
version of C, and feels like java in a way.
Things have changed since TDPL was created but here is the errata which
says what[0].
However;
Ive run into a bit of a problem while writing some code. Im not sure if
Im doing something wrong, or maybe the things Im using are depreciated??
Code Blocks does not give any messages as to what is going wrong. I
haven't configured anything, and am not familiar with messing around
with IDE settings.
Its directly based off of the example on page 8.
here is the code that does not compile:
import std.stdio, std.string;
void main() { ... }
void dict() {
uint[string] dictionary;
foreach(line; stdin.byLine()) {
//chunk = splitter(strip(line); ## errors because of splitter
foreach(word; splitter(strip(line))) { ## errors because of
splitter ??
if(word in dictionary) continue;
//writeln(dictionary.length); ## gives 0 ??
auto newID = dictionary.length;
dictionary[word] = newId;
writeln(newID, ' ', word);
}
}
}
Im not sure what Im doing wrong here.
modifying the code to just print the result of splitLines results in the
entire line.
and just having splitter give a sting to print also errors.
Please help, thanks!
Oh splitter is in std.algorithm.iteration[1].
Import it and it should work.
[0] http://erdani.com/tdpl/errata/
[1] http://dlang.org/phobos/std_algorithm_iteration.html#.splitter