www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - string comparison

reply doubleagent <doubleagent03 gmail.com> writes:
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
Dec 18 2010
next sibling parent reply doubleagent <doubleagent03 gmail.com> writes:
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?
Dec 19 2010
next sibling parent reply Stanislav Blinov <blinov loniir.ru> writes:
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.
Dec 20 2010
next sibling parent doubleagent <doubleagent03 gmail.com> writes:
I understand.  Thank you, and thanks for pointing out the chatroom.
Dec 20 2010
prev sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Mon, 20 Dec 2010 11:13:34 -0500, Stanislav Blinov <blinov loniir.ru>  
wrote:

 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, this message board is not moderated. -Steve
Dec 20 2010
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Mon, 20 Dec 2010 14:05:56 -0500, Steven Schveighoffer  
<schveiguy yahoo.com> wrote:

 On Mon, 20 Dec 2010 11:13:34 -0500, Stanislav Blinov <blinov loniir.ru>  
 wrote:

 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, this message board is not moderated.
I should clarify, it's retroactively moderated :) That is, if spam appears, it's allowed to go through, but then removed once discovered. -Steve
Dec 20 2010
parent reply Stanislav Blinov <blinov loniir.ru> writes:
20.12.2010 22:06, Steven Schveighoffer пишет:
 On Mon, 20 Dec 2010 14:05:56 -0500, Steven Schveighoffer 
 <schveiguy yahoo.com> wrote:

 On Mon, 20 Dec 2010 11:13:34 -0500, Stanislav Blinov 
 <blinov loniir.ru> wrote:

 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, this message board is not moderated.
I should clarify, it's retroactively moderated :) That is, if spam appears, it's allowed to go through, but then removed once discovered.
Citing what I got when first posted from my current address: ... Your mail to 'Digitalmars-d-learn' with the subject Re: hijacking a class's members Is being held until the list moderator can review it for approval. The reason it is being held: Post to moderated list Either the message will get posted to the list, or you will receive notification of the moderator's decision. If you would like to cancel this posting, please visit the following URL: ... I should note that I post via mailing list, so maybe this is the catch.
Dec 21 2010
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 21 Dec 2010 11:12:00 -0500, Stanislav Blinov <blinov loniir.ru>  
wrote:

 20.12.2010 22:06, Steven Schveighoffer пишет:
 On Mon, 20 Dec 2010 14:05:56 -0500, Steven Schveighoffer  
 <schveiguy yahoo.com> wrote:

 On Mon, 20 Dec 2010 11:13:34 -0500, Stanislav Blinov  
 <blinov loniir.ru> wrote:

 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, this message board is not moderated.
I should clarify, it's retroactively moderated :) That is, if spam appears, it's allowed to go through, but then removed once discovered.
Citing what I got when first posted from my current address: ... Your mail to 'Digitalmars-d-learn' with the subject Re: hijacking a class's members Is being held until the list moderator can review it for approval. The reason it is being held: Post to moderated list Either the message will get posted to the list, or you will receive notification of the moderator's decision. If you would like to cancel this posting, please visit the following URL: ... I should note that I post via mailing list, so maybe this is the catch.
Hm... I always use a newsgroup client, so maybe. But in any case, I've never known anyone to have been blocked from posting, and the newsgroup interface does not have any moderation on it. I'd be surprised if anyone with the ability to moderate spends any time moderating the newsgroup. That might be a canned message. -Steve
Dec 21 2010
next sibling parent spir <denis.spir gmail.com> writes:
On Tue, 21 Dec 2010 11:49:42 -0500
"Steven Schveighoffer" <schveiguy yahoo.com> wrote:

 Hm... I always use a newsgroup client, so maybe.  But in any case, I've =
=20
 never known anyone to have been blocked from posting, and the newsgroup =
=20
 interface does not have any moderation on it.  I'd be surprised if anyone=
=20
 with the ability to moderate spends any time moderating the newsgroup.
Mailing list neither (never got any moderation message). Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com
Dec 21 2010
prev sibling parent Stanislav Blinov <blinov loniir.ru> writes:
21.12.2010 19:55, spir пишет:
 On Tue, 21 Dec 2010 11:49:42 -0500
 "Steven Schveighoffer"<schveiguy yahoo.com>  wrote:

 Hm... I always use a newsgroup client, so maybe.  But in any case, I've
 never known anyone to have been blocked from posting, and the newsgroup
 interface does not have any moderation on it.  I'd be surprised if anyone
 with the ability to moderate spends any time moderating the newsgroup.
Mailing list neither (never got any moderation message).
With newsgroups, I never got the moderation warning either. But I did get that moderation message and then waited almost a day to see my message in the list. But this happened only to the first message in each list.
Dec 21 2010
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
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
Dec 20 2010
prev sibling next sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
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
Dec 19 2010
next sibling parent "Denis Koroskin" <2korden gmail.com> writes:
Check your client setting, everything is perfect on my side (Opera  
built-in news client).
Dec 19 2010
prev sibling parent doubleagent <doubleagent03 gmail.com> writes:
 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.
Thanks. The code was pretty self-explanatory but it's helpful to know that auto functions currently don't get documented.
Dec 20 2010
prev sibling next sibling parent reply "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
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
Dec 20 2010
next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
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
Dec 20 2010
prev sibling parent reply doubleagent <doubleagent03 gmail.com> writes:
 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?
Dec 20 2010
next sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Monday, December 20, 2010 10:44:12 doubleagent wrote:
 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.
Okay. I don't know what the actual code looks like, but word is obviously a dynamic array, and if it's from byLine(), then that dynamic array is mutable - both the array itself and its elements. Using idup gets you an immutable copy. When copying dynamic arrays, you really get a slice of that array. So, you get an array that points to the same array as the original. Any changes to the elements in one affects the other. If you append to one of them and it doesn't have the space to resize in place or dyou o anything else which could cause it to reallocate, then that array is reallocated and they no longer point to the same data and changing will not change the other. If the elements of the array are const or immutable, then the fact that the two arrays point to the same data isn't a problem because the elements can't be changed (except in cases where you'red dealing with const rather than immutable and another array points to the same data but doesn't have const elements). So, assigning one string to another, for instance (string being an alias for immutable(char)[]), will never result in one string altering another. However, if you're dealing with char[] rather than string, one array _can_ affect the elements of another. I believe that byLine() deals with a char[], not a string. Now, as for associative arrays, they don't really deal with const correctly. I believe that they're actually implemented with void* and you can actually do things like put const elements in them in spite of the fact that toHash() on Object is not currently const (there is an open bug on the fact that Object is not const-correct). So, it does not surprise me in the least if it will take mutable types as its key and then allow them to be altered (assuming that they're pointers or reference types and you can therefore have other references to them). But to fix the problem in this case would require immutability rather than const, because you're dealing with a reference type (well, pseudo-reference type since dynamic arrays share their elements such that changes to their elements affect all arrays which point to those elements, but other changes - such as altering their length don't affect other arrays and will even likely result in the arrays then being completely separate).
 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.
in should use toHash() (or whatever built-in functions for built-in types if you're not dealing with a struct or class) followed by ==. I'd be stunned if there were any caching involved. The problem is that byLine() is using a mutable array, so the elements pointed to by the array that you just put in the associative array changed, which means that the hash for them is wrong, and == will fail when used to compare the array to what it was before.
 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?
C compatability would be one reason. Familiarity would be another. Also, it would be _really_ annoying to have to mark variables mutable all over the place as you would inevitably have to do. The way that const and immutable are designed in D, to some extent, you can pretty much ignore them if you don't want to use them, which some folks like Andrei deem important. Making immutable the default would force it on everyone. - Jonathan M Davis
Dec 20 2010
parent reply doubleagent <doubleagent03 gmail.com> writes:
 Okay. I don't know what the actual code looks like
Here. import std.stdio, std.string; void main() { uint[string] dictionary; // v[k], so string->uint 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; writefln("%s\t%s", newId, word); } } }
 ...
Okay, suppose you're right. The behavior is still incorrect because the associative array has allowed two identical keys...identical because the only difference between two strings which I care about are the contents of their character arrays.
 Also, it
 would be _really_ annoying to have to mark variables mutable all over the place
 as you would inevitably have to do.
Obviously your other points are valid, but I haven't found this to be true (Clojure is pure joy). Maybe you're right because D is a systems language and mutability needs to be preferred, however after only a day or two of exposure to this language that assumption also appears to be wrong. Take a look at Walter's first attempted patch to bug 2954: 13 lines altered to explicitly include immutable, and 4 altered to treat variables as const: http://www.dsource.org/projects/dmd/changeset/749 But I'm willing to admit that my exposure is limited, and that particular example is a little biased.
Dec 20 2010
parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Monday, December 20, 2010 16:45:20 doubleagent wrote:
 Okay. I don't know what the actual code looks like
Here. import std.stdio, std.string; void main() { uint[string] dictionary; // v[k], so string->uint 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; writefln("%s\t%s", newId, word); } } }
 ...
Okay, suppose you're right. The behavior is still incorrect because the associative array has allowed two identical keys...identical because the only difference between two strings which I care about are the contents of their character arrays.
Array comparison cares about the contents of the array. It may shortcut comparisons if lengths differ or if they point to the same point in memory and have the same length, but array comparison is all about comparing their elements. In this case, you'd have two arrays/strings which point to the same point in memory but have different lengths. Because their lengths differ, they'd be deemed unequal. If you managed to try and put a string in the associative array which has the same length as one that you already inserted, then they'll be considered equal, since their lengths are identical and they point to same point in memory, so in that case, I would expect the original value to be replaced with the new one. But other than that, the keys will be considered unequal in spite of the fact that they point to the same place in memory. The real problem here is that associative arrays currently allow non-immutable keys. Once that's fixed, then it won't be a problem anymore.
 Also, it
 would be _really_ annoying to have to mark variables mutable all over the
 place as you would inevitably have to do.
Obviously your other points are valid, but I haven't found this to be true (Clojure is pure joy). Maybe you're right because D is a systems language and mutability needs to be preferred, however after only a day or two of exposure to this language that assumption also appears to be wrong. Take a look at Walter's first attempted patch to bug 2954: 13 lines altered to explicitly include immutable, and 4 altered to treat variables as const: http://www.dsource.org/projects/dmd/changeset/749 But I'm willing to admit that my exposure is limited, and that particular example is a little biased.
Most programmers don't use const even in languages that have it. And with many pretty limited), many, many programmers never use const and see no value in it. So, for most programmers, mutable variables will be the norm, and they'll likely only use const or immutable if they have to. There are plenty of C++ programmers who will seek to use const (and possibly immutable) heavily, but they're definitely not the norm. And, of course, there are plenty of other languages out there with const or immutable types of one sort or another (particularly most functional languages), but those aren't the types of languages that most programmers use. The result is that most beginning D programmers will be looking for mutable to be the norm, and forcing const and/or immutable on them could be seriously off- putting. Now, most code which is going to actually use const and immutable is likely to be a fair mix of mutable, const, and immutable - especially if you don't try to make everything immutable at the cost of efficiency like you'd typically get in a functional language. That being the case, regardless of whether mutable, const, or immutable is the default, you're going to have to mark a fair number of variables as something other than the default. So, making const or immutable the default would likely not save any typing, and it would annoy a _lot_ of programmers. So, the overall gain of making const or immutable the default is pretty minimal if not outright negative. Personally, I use const and immutable a lot, but I still wouldn't want const or immutable to be the default. - Jonathan M Davis
Dec 20 2010
parent doubleagent <doubleagent03 gmail.com> writes:
Good & I agree.
Dec 20 2010
prev sibling parent reply "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
On Mon, 20 Dec 2010 18:44:12 +0000, doubleagent wrote:

 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.
This could be related to bug 2954, for which a fix will be released in the next version of DMD. http://d.puremagic.com/issues/show_bug.cgi?id=2954 -Lars
Dec 20 2010
parent doubleagent <doubleagent03 gmail.com> writes:
 This could be related to bug 2954, for which a fix will be released in
 the next version of DMD.
Looking at that new descriptive error message ie error("associative arrays can only be assigned values with immutable keys, not %s", e2->type->toChars()); it appears to be a distinct possibility. Thanks.
Dec 20 2010
prev sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Tuesday, December 21, 2010 09:36:20 Stanislav Blinov wrote:
 21.12.2010 19:55, spir =D0=BF=D0=B8=D1=88=D0=B5=D1=82:
 On Tue, 21 Dec 2010 11:49:42 -0500
=20
 "Steven Schveighoffer"<schveiguy yahoo.com>  wrote:
 Hm... I always use a newsgroup client, so maybe.  But in any case, I've
 never known anyone to have been blocked from posting, and the newsgroup
 interface does not have any moderation on it.  I'd be surprised if
 anyone with the ability to moderate spends any time moderating the
 newsgroup.
=20 Mailing list neither (never got any moderation message).
=20 With newsgroups, I never got the moderation warning either. But I did get that moderation message and then waited almost a day to see my message in the list. But this happened only to the first message in each list.
The first message sent to the list has to be okayed by Brad. That way, he h= as a=20 way to stop spam bots. When he sees that you at least appear to be a real=20 person, he lets your first e-mail through and then changes whatever setting= s he=20 has to to make it so that the list then just accepts your e-mails. But sinc= e he=20 has to do it personally, there can be a delay between when you send your fi= rst=20 message and when it arrives. I believe that that occurs once per list that = you=20 sign up for. The only other time that I've seen moderation messages are when I've sent=20 messages that are too large (because of attachments with code), at which po= int=20 Brad has to approve it. In general though, it's preferred that you post a l= ink=20 to code rather than attach it (which I didn't know at the time). You typically shouldn't be seeing moderator messages. =2D Jonathan M Davis
Dec 21 2010
next sibling parent doubleagent <doubleagent03 gmail.com> writes:
 In general though, it's preferred that you post a link to code rather than
attach it
I'll try to remember that.
Dec 21 2010
prev sibling parent Stanislav Blinov <stanislav.blinov gmail.com> writes:
On 12/21/2010 10:51 PM, Jonathan M Davis wrote:

 With newsgroups, I never got the moderation warning either.
 But I did get that moderation message and then waited almost a day to
 see my message in the list. But this happened only to the first message
 in each list.
The first message sent to the list has to be okayed by Brad. That way, he has a way to stop spam bots. When he sees that you at least appear to be a real person, he lets your first e-mail through and then changes whatever settings he has to to make it so that the list then just accepts your e-mails. But since he has to do it personally, there can be a delay between when you send your first message and when it arrives. I believe that that occurs once per list that you sign up for. The only other time that I've seen moderation messages are when I've sent messages that are too large (because of attachments with code), at which point Brad has to approve it. In general though, it's preferred that you post a link to code rather than attach it (which I didn't know at the time). You typically shouldn't be seeing moderator messages.
Thanks for clarification. I already started to wonder if it was just me :)
Dec 22 2010