string comparison

Jonathan M Davis jmdavisProg at gmx.com
Mon Dec 20 10:07:13 PST 2010


On Monday, December 20, 2010 06:01:23 Lars T. Kyllingstad wrote:
> On Sun, 19 Dec 2010 07:01:30 +0000, doubleagent wrote:
> > Andrei's quick dictionary illustration [in his book, 'The D Programming
> > Language'] doesn't seem to work.  Code attached.
> 
> That's strange.  I ran the example you posted using DMD 2.050 myself, and
> it works for me.  Are you 100% sure that you are running this version,
> and that it is not using an outdated Phobos version (from an older
> installation, for instance)?
> 
> One suggestion:  Try replacing the next-to-last line with this:
> 
>   dictionary[word.idup] = newId;
> 
> The 'word' array is mutable and reused by byLine() on each iteration.  By
> doing the above you use an immutable copy of it as the key instead.
> 
> > On my computer, with d2-0.5.0, I got the following output while testing.
> > 
> > andrei
> > 0	andrei
> > 
> >  andrei
> > 
> > 1	andrei
> > 
> > 
> > Also, why doesn't 'splitter' show up on the site's documentation of
> > std.string?  And what advantage does 'splitter(strip(line))' offer over
> > 'split(line)'?
> 
> splitter is defined in std.algorithm.  The fact that it becomes visible
> when you import std.string is due to bug 314:
> 
>   http://d.puremagic.com/issues/show_bug.cgi?id=314
> 
> (std.string is supposed to publically import just a few symbols from
> std.algorithm, but because of this bug the whole module gets imported
> publically.)

Actually, while that is a definite bug, splitter() _is_ defined in std.string as 
well (though it calls std.algorithm.splitter()), but it returns auto, so it 
doesn't show up in the docs, which is a different bug.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list