problems with DPL example.

%u foo.bar at yahoo.com
Mon Oct 10 11:10:16 PDT 2011


== Quote from simendsjo (simendsjo at gmail.com)'s article
> Seems some functionality was moved in 2.052. From std.string
documentation:
> "IMPORTANT NOTE: Beginning with version 2.052, the following
symbols
> have been generalized beyond strings and moved to different
modules."
> And
> "split	Use std.array.split instead"
> std.array includes both split and splitter.
> http://www.d-programming-language.org/phobos/std_array.html#split



Okay, thanks for that.  I added the extra module, and found I made
a typo.  So I corrected that too.  Anyways, I am now having another
problem.  What can I do to fix it? :




import std.stdio, std.string, std.array;

void main() {
  uint[string] dictionary;

  foreach( line; stdin.byLine()) {
    // Break sentence into words
    // Add each word in the sentence to the vocabulary
    foreach( word; splitter(strip(line))) {
      if( word in dictionary) continue; // Nothing to do.
      auto newID = dictionary.length;
      dictionary[word] = newID;
      writeln( newID, '\t', word);
    }
  }
  return;
}




$ dmd wordcount.d
wordcount.d(12): Error: associative arrays can only be assigned
values with immutable keys, not char[]


$ dmd -v
DMD32 D Compiler v2.055
Copyright (c) 1999-2011 by Digital Mars written by Walter Bright
Documentation: http://www.digitalmars.com/d/2.0/index.html
Usage:




thanks!


More information about the Digitalmars-d-learn mailing list