Re: string and char[]

2011-04-08 Thread Steven Schveighoffer
On Fri, 08 Apr 2011 16:12:27 -0400, spir wrote: On 04/08/2011 09:20 PM, Steven Schveighoffer wrote: In reality, most times you are not using something as a key and somewhere else simultaneously. So while theoretically dangerous, it's easy to write code that isn't dangerous. What about

Re: string and char[]

2011-04-08 Thread spir
On 04/08/2011 09:20 PM, Steven Schveighoffer wrote: On Fri, 08 Apr 2011 14:57:52 -0400, spir wrote: On 04/08/2011 03:13 PM, Steven Schveighoffer wrote: On Fri, 08 Apr 2011 06:44:42 -0400, Simen kjaeraas wrote: On Fri, 08 Apr 2011 12:46:08 +0200, Morlan wrote: It is OK if I write int[ch

Re: string and char[]

2011-04-08 Thread Steven Schveighoffer
On Fri, 08 Apr 2011 14:57:52 -0400, spir wrote: On 04/08/2011 03:13 PM, Steven Schveighoffer wrote: On Fri, 08 Apr 2011 06:44:42 -0400, Simen kjaeraas wrote: On Fri, 08 Apr 2011 12:46:08 +0200, Morlan wrote: It is OK if I write int[char[]] asr; asr["hello"] = 10; but the following do

Re: string and char[]

2011-04-08 Thread spir
On 04/08/2011 03:40 PM, Denis Koroskin wrote: What about storing objects as keys? There is nothing wrong to modify those objects as long as their order stays the same. I think if referenced objects are to be used as keys, they should be compared by pointer/identity (hash would return their add

Re: string and char[]

2011-04-08 Thread spir
On 04/08/2011 03:13 PM, Steven Schveighoffer wrote: On Fri, 08 Apr 2011 06:44:42 -0400, Simen kjaeraas wrote: On Fri, 08 Apr 2011 12:46:08 +0200, Morlan wrote: It is OK if I write int[char[]] asr; asr["hello"] = 10; but the following does not compile: char[] car = "hello"; What is the

Re: string and char[]

2011-04-08 Thread Jesse Phillips
On Fri, 08 Apr 2011 17:40:32 +0400, Denis Koroskin wrote: > int compare(char[] lhs, char[] rhs) pure { > if (lhs < rhs) return 1; > if (lhs > rhs) return -1; > return 0; > } > > is not. > > For some reason (bug?), both compile with 2.052. Purity has nothing to do with the type. "

Re: string and char[]

2011-04-08 Thread Steven Schveighoffer
On Fri, 08 Apr 2011 09:40:32 -0400, Denis Koroskin <2kor...@gmail.com> wrote: On Fri, 08 Apr 2011 17:13:19 +0400, Steven Schveighoffer wrote: On Fri, 08 Apr 2011 06:44:42 -0400, Simen kjaeraas wrote: On Fri, 08 Apr 2011 12:46:08 +0200, Morlan wrote: It is OK if I write int[char

Re: string and char[]

2011-04-08 Thread Denis Koroskin
On Fri, 08 Apr 2011 17:13:19 +0400, Steven Schveighoffer wrote: On Fri, 08 Apr 2011 06:44:42 -0400, Simen kjaeraas wrote: On Fri, 08 Apr 2011 12:46:08 +0200, Morlan wrote: It is OK if I write int[char[]] asr; asr["hello"] = 10; but the following does not compile: char[] car =

Re: string and char[]

2011-04-08 Thread Steven Schveighoffer
On Fri, 08 Apr 2011 06:44:42 -0400, Simen kjaeraas wrote: On Fri, 08 Apr 2011 12:46:08 +0200, Morlan wrote: It is OK if I write int[char[]] asr; asr["hello"] = 10; but the following does not compile: char[] car = "hello"; What is the explanation for this behaviour? The first sh

Re: string and char[]

2011-04-08 Thread Morlan
Of course, by saying it should not compile I mean things like asr["hello"] should not compile.

Re: string and char[]

2011-04-08 Thread Simen kjaeraas
On Fri, 08 Apr 2011 13:37:10 +0200, Morlan wrote: int[char[]] is consistently used D's Language reference to illustrate associative arrays. For me it looks like something that should not compile. Of course int[string] works without problem so I wonder why int[char[]] was used as an example. Was

Re: string and char[]

2011-04-08 Thread Morlan
int[char[]] is consistently used D's Language reference to illustrate associative arrays. For me it looks like something that should not compile. Of course int[string] works without problem so I wonder why int[char[]] was used as an example. Was it carried over from D1 reference perhaps?

Re: string and char[]

2011-04-08 Thread Simen kjaeraas
On Fri, 08 Apr 2011 13:01:41 +0200, simendsjo wrote: It is a mistake to use non-immutable keys for an associative array. But a string literal isn't mutable..? This is correct. I'm referring to line 1, int[char[]] asr;. This declaration is wrong, and should be rejected by the compiler. Al

Re: string and char[]

2011-04-08 Thread simendsjo
> It is a mistake to use non-immutable keys for an associative array. But a string literal isn't mutable..?

Re: string and char[]

2011-04-08 Thread Simen kjaeraas
On Fri, 08 Apr 2011 12:46:08 +0200, Morlan wrote: It is OK if I write int[char[]] asr; asr["hello"] = 10; but the following does not compile: char[] car = "hello"; What is the explanation for this behaviour? The first should not be allowed. It is a mistake to use non-immutable keys

string and char[]

2011-04-08 Thread Morlan
It is OK if I write int[char[]] asr; asr["hello"] = 10; but the following does not compile: char[] car = "hello"; What is the explanation for this behaviour?