Re: Principled method of lookup-or-insert in associative arrays?

2010-12-02 Thread Bruno Medeiros
On 02/12/2010 14:18, Bruno Medeiros wrote: On 20/11/2010 08:07, Andrei Alexandrescu wrote: TDPL has an example that can be reduced as follows: void main() { uint[string] map; foreach (line; stdin.byLine()) { ++map[line]; } } byLine reuses its buffer so it exposes it as char[]. Therefore, attem

Re: Principled method of lookup-or-insert in associative arrays?

2010-12-02 Thread Bruno Medeiros
On 20/11/2010 08:07, Andrei Alexandrescu wrote: TDPL has an example that can be reduced as follows: void main() { uint[string] map; foreach (line; stdin.byLine()) { ++map[line]; } } byLine reuses its buffer so it exposes it as char[]. Therefore, attempting to use map[line] will fail. The progra

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-21 Thread Fawzi Mohamed
I was thinking about this, and revised my idea. While I think that in general hiding idup is a bad practice, I think that for AA one could make the case that it might be acceptable. idup is needed only when assigning a value using a key that isn't immutable. Now I think that this use in AA is

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Michel Fortin
On 2010-11-20 18:04:29 -0500, "Tyro[a.c.edwards]" said: On 11/20/2010 9:39 PM, Michel Fortin wrote: But didn't you agree with me yesterday in another thread that it's best to make the caller responsible for the idup in cases where you need a string to be immutable? Now you want the reverse for

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Tyro[a.c.edwards]
On 11/21/2010 10:39 AM, Tomek Sowiński wrote: Dnia 21-11-2010 o 02:02:35 Tyro[a.c.edwards] napisał(a): The harm is confusion. Now = on arrays always means aliasing, but with your proposal, it may *sometimes* mean dupping. Imagine real-life code with type aliasing and type inference in play, an

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Tomek Sowiński
Dnia 21-11-2010 o 02:02:35 Tyro[a.c.edwards] napisał(a): The harm is confusion. Now = on arrays always means aliasing, but with your proposal, it may *sometimes* mean dupping. Imagine real-life code with type aliasing and type inference in play, and trying to determine whether some line makes a

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Tyro[a.c.edwards]
On 11/21/2010 9:23 AM, Tomek Sowiński wrote: Tyro[a.c.edwards] napisał(a): What would be the harm if upon seeing your code the compiler did this: char[] chars = "abc".dup; char[] backdoor = chars; string s = chars.idup; assert (s == "abc"); backdoor.front = 'k'; // [1] assert (s == "abc"); Sli

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Tomek Sowiński
Tyro[a.c.edwards] napisał(a): What would be the harm if upon seeing your code the compiler did this: char[] chars = "abc".dup; char[] backdoor = chars; string s = chars.idup; assert (s == "abc"); backdoor.front = 'k'; // [1] assert (s == "abc"); Slightly magical but works according to expec

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Tyro[a.c.edwards]
On 11/20/2010 9:39 PM, Michel Fortin wrote: On 2010-11-20 03:07:57 -0500, Andrei Alexandrescu said: TDPL has an example that can be reduced as follows: void main() { uint[string] map; foreach (line; stdin.byLine()) { ++map[line]; } } byLine reuses its buffer so it exposes it as char[]. There

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Tyro[a.c.edwards]
On 11/20/2010 11:22 PM, Tomek Sowiński wrote: Dnia 20-11-2010 o 13:33:29 spir napisał(a): I find this proposal really necessary. But aren't there two issues here? * Comparison (for lookup) by value equality should not care about qualifiers (ie compare raw content, here plain array memory areas

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread spir
On Sat, 20 Nov 2010 21:21:58 +0100 Tomek Sowiński wrote: > Dnia 20-11-2010 o 17:09:00 spir napisał(a): > > >> It's busting the whole const system to smithereens. > >> > >> char[] chars = "abc"; > >> char[] backdoor = chars; > >> string s = chars; > >> assert (s == "abc"); > >> backdoor.front =

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Tomek Sowiński
Dnia 20-11-2010 o 17:09:00 spir napisał(a): It's busting the whole const system to smithereens. char[] chars = "abc"; char[] backdoor = chars; string s = chars; assert (s == "abc"); backdoor.front = 'k'; assert (s == "abc"); // fails. not so immutable, huh? ??? backdoor and s do not denote th

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Adam Burton
spir wrote: > On Sat, 20 Nov 2010 15:22:37 +0100 > Tomek Sowiński wrote: > >> > I find this proposal really necessary. But aren't there two issues >> > here? * Comparison (for lookup) by value equality should not care about >> > qualifiers (ie compare raw content, here plain array memory areas).

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Pelle Månsson
On 11/20/2010 05:09 PM, spir wrote: ??? backdoor and s do not denote the same element. One is a mutable array, the other is immutable. Why should changing backdoor affect s? Whether backdoor and chars denote the same array depends on whether "=" copies or not dyn arrays. But from immutable str

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread spir
On Sat, 20 Nov 2010 15:22:37 +0100 Tomek Sowiński wrote: > > I find this proposal really necessary. But aren't there two issues here? > > * Comparison (for lookup) by value equality should not care about > > qualifiers (ie compare raw content, here plain array memory areas). > > * Assignment sh

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Tomek Sowiński
Andrei Alexandrescu napisał(a): TDPL has an example that can be reduced as follows: void main() { uint[string] map; foreach (line; stdin.byLine()) { ++map[line]; } } byLine reuses its buffer so it exposes it as char[]. Therefore, attempting to use map[line] will fail. The prog

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Tomek Sowiński
Dnia 20-11-2010 o 13:33:29 spir napisał(a): I find this proposal really necessary. But aren't there two issues here? * Comparison (for lookup) by value equality should not care about qualifiers (ie compare raw content, here plain array memory areas). * Assignment should perform "qualificatio

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Michel Fortin
On 2010-11-20 03:07:57 -0500, Andrei Alexandrescu said: TDPL has an example that can be reduced as follows: void main() { uint[string] map; foreach (line; stdin.byLine()) { ++map[line]; } } byLine reuses its buffer so it exposes it as char[]. Therefore, attempting to use map[l

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread spir
On Sat, 20 Nov 2010 00:07:57 -0800 Andrei Alexandrescu wrote: > TDPL has an example that can be reduced as follows: > > void main() { >uint[string] map; >foreach (line; stdin.byLine()) { > ++map[line]; >} > } > > byLine reuses its buffer so it exposes it as char[]. Therefore,

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Fawzi Mohamed
On 20-nov-10, at 09:07, Andrei Alexandrescu wrote: TDPL has an example that can be reduced as follows: void main() { uint[string] map; foreach (line; stdin.byLine()) { ++map[line]; } } byLine reuses its buffer so it exposes it as char[]. Therefore, attempting to use map[line] will f

Re: Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Lutger Blijdestijn
Andrei Alexandrescu wrote: > TDPL has an example that can be reduced as follows: > > void main() { >uint[string] map; >foreach (line; stdin.byLine()) { > ++map[line]; >} > } > > byLine reuses its buffer so it exposes it as char[]. Therefore, > attempting to use map[line] will fa

Principled method of lookup-or-insert in associative arrays?

2010-11-20 Thread Andrei Alexandrescu
TDPL has an example that can be reduced as follows: void main() { uint[string] map; foreach (line; stdin.byLine()) { ++map[line]; } } byLine reuses its buffer so it exposes it as char[]. Therefore, attempting to use map[line] will fail. The program compiled and did the wrong thing be