> Are you 100% sure that you are running this version

I have to be.  There are no other versions of phobos on this box and 'which dmd'
points to the correct binary.

>  dictionary[word.idup] = newId;

That fixes it.

> 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.

I REALLY don't understand this explanation.  Why does the mutability of 'word'
matter when the associative array 'dictionary' assigns keys by value...it's got 
to
assign them by value, right?  Otherwise we would only get one entry in
'dictionary' and the key would be constantly changing.

The behavior itself seems really unpredictable prior to testing, and really
unintended after testing.  I suspect it's due to some sort of a bug.  The 
program,
on my box anyway, only fails when we give it identical strings, except one is
prefixed with a space.  That should tell us that 'splitter' and 'strip' didn't 
do
their job properly.  The fly in the ointment is that when we output the strings,
they appear as we would expect.

I suspect D does string comparisons (when the 'in' keyword is used) based on 
some
kind of a hash, and that hash doesn't get correctly updated when 'strip' or
'splitter' is applied, or upon the next comparison or whatever.  Calling 'idup'
must force the hash to get recalculated.  Obviously, you guys would know if
there's any merit to this, but it seems to explain the problem.

> The advantage with splitter is that it is lazy and therefore more
> efficient.  split() is eager and allocates memory to hold the string
> fragments.

Yeah, that's what I thought would be the answer.  Kudos to you guys for thinking
of laziness out of the box.  This is a major boon for D.

You know, there's something this touches on which I was curious about.  If D
defaults to 'safety first', and with some work you can get down-to-the-metal, 
why
doesn't the language default to immutable variables, with an explicit modifier 
for
mutable ones?  C compatibility?

Reply via email to