Jump to page: 1 2 3
Thread overview
string comparison
Dec 19, 2010
doubleagent
Dec 20, 2010
doubleagent
Dec 20, 2010
Stanislav Blinov
Dec 20, 2010
doubleagent
Dec 21, 2010
Stanislav Blinov
Dec 21, 2010
spir
Dec 21, 2010
Stanislav Blinov
Dec 20, 2010
Jonathan M Davis
Dec 20, 2010
Denis Koroskin
Dec 20, 2010
doubleagent
Dec 20, 2010
Jonathan M Davis
Dec 20, 2010
doubleagent
Dec 20, 2010
Jonathan M Davis
Dec 21, 2010
doubleagent
Dec 21, 2010
Jonathan M Davis
Dec 21, 2010
doubleagent
Dec 21, 2010
doubleagent
Dec 21, 2010
Jonathan M Davis
Dec 22, 2010
doubleagent
Dec 22, 2010
Stanislav Blinov
December 19, 2010
Andrei's quick dictionary illustration [in his book, 'The D Programming Language'] doesn't seem to work.  Code attached.

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)'?
December 20, 2010
Compared to the relatively snappy response other threads have been receiving I'm going to assume that nobody is interested in my inquiry.

That's cool.  Can anybody point me to an IRC chatroom for D noobs, and is there anywhere to post errata for the book?
December 20, 2010
On Saturday 18 December 2010 23:01:30 doubleagent wrote:
> Andrei's quick dictionary illustration [in his book, 'The D Programming Language'] doesn't seem to work.  Code attached.
> 
> 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)'?
> begin 644 dictionary.d
> M:6UP;W)T('-T9"YS=&1I;RP@<W1D+G-T<FEN9SL*"G9O:60@;6%I;B@I('L*
> M"75I;G1;<W1R:6YG72!D:6-T:6]N87)Y.R`O+R!V6VM=+"!S;R!S=')I;F<M
> M/G5I;G0*"69O<F5A8V@@*&QI;F4[('-T9&EN+F)Y3&EN92@I*2!["@D)+R\@
> M8G)E86L@<V5N=&5N8V4@:6YT;R!W;W)D<PH)"2\O($%D9"!E86-H('=O<F0@
> M:6X@=&AE('-E;G1E;F-E('1O('1H92!V;V-A8G5L87)Y"@D)9F]R96%C:"`H
> M=V]R9#L@<W!L:71T97(H<W1R:7`H;&EN92DI*2!["@D)"6EF("AW;W)D(&EN
> M(&1I8W1I;VYA<GDI(&-O;G1I;G5E.R`O+R!N;W1H:6YG('1O(&1O"@D)"6%U
> M=&\@;F5W260@/2!D:6-T:6]N87)Y+FQE;F=T:#L*"0D)9&EC=&EO;F%R>5MW
> M;W)D72`](&YE=TED.PH)"0EW<FET969L;B@B)7-<="5S(BP@;F5W260L('=O
> .<F0I.PH)"7T*"7T*?0H`
> `
> end

Whatever you did to attach your code, it just comes up as gibberish to me. The errata page is here: http://erdani.com/tdpl/errata/index.php?title=Main_Page I have no idea what example you're looking at, or what the problem is. There are some examples in the book which are not 100% correct (most, if not all of them, are in the errata) and a few which don't work yet due to bugs in dmd or features which are not completely implemented yet (e.g. currently, you can only have one alias this per class/struct, but TDPL says that you can have multiple).

The reason that std.string.splitter() does not show in the documentation is that its return type is auto, and there is currently a bug in ddoc that makes it so that auto functions don't end up in the generated documentation. Looking at the code, it pretty much just forwards to std.algorithm.splitter() using whitespace as its separator, so you can look at the documentation there if you'd like.

Looking at the code for std.algorithm.splitter(), I'd say that the main
advantage of splitter() over split() is that it generates a lazy range. So, if
you don't want to process the whole range or if you don't want to use as much
memory by having to duplicate the entire range that you passed to
split()/splitter(), then you'd use splitter(). split() does have the advantage
that it gives you an array, so you don't have to use std.array.array() if you
want an array, like you'd have to do with splitter().

Overall, splitter() is more generic. split() is specific to std.string, and
std.string has a version of splitte() presumably so that there is a version
which matches up with split()'s behavior.

- Jonathan M Davis
December 20, 2010
Check your client setting, everything is perfect on my side (Opera built-in news client).
December 20, 2010
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.)

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

-Lars
December 20, 2010
20.12.2010 8:35, doubleagent пишет:
> Compared to the relatively snappy response other threads have been receiving I'm
> going to assume that nobody is interested in my inquiry.
>
> That's cool.  Can anybody point me to an IRC chatroom for D noobs, and is there
> anywhere to post errata for the book?
>
Please don't feel offended if you don't get response quickly. Even if it may seem that people are active in other threads doesn't mean they are fast enough to analyse arising questions and problems while discussing some recent ideas and improvements and not forgetting to work and sleep ;)
Besides, there are many people here from different parts of the world, different time zones.

And lastly, hasn't this by chance been your first post? AFAIR, the first message is being moderated so it doesn't get to the public at once.

BTW, There is a #D channel on freenode, if my memory serves.
December 20, 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
December 20, 2010
On Mon, 20 Dec 2010 00:35:53 -0500, doubleagent <doubleagent03@gmail.com> wrote:

> Compared to the relatively snappy response other threads have been receiving I'm
> going to assume that nobody is interested in my inquiry.

Just a tip, don't expect snappy responses on Sunday...  We all have lives you know ;)  I for one usually have my computer that I do D stuff with off for most of the weekend.

-Steve
December 20, 2010
> 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?
December 20, 2010
I understand.  Thank you, and thanks for pointing out the chatroom.
« First   ‹ Prev
1 2 3