Re: associative arrays: iteration is finally here

2009-10-30 Thread Pelle Månsson
Nick Sabalausky wrote: "Pelle Månsson" wrote in message news:hcaaro$15e...@digitalmars.com... I think foreach should be consistent with opIn, that is, if (foo in aa) { //it is in the aa. foreach (f; aa) { // loop over each item in the aa //I expect foo to show up in here, since it is "in"

Re: associative arrays: iteration is finally here

2009-10-29 Thread Nick Sabalausky
"bearophile" wrote in message news:hca087$dv...@digitalmars.com... > Andrei Alexandrescu: > >> That is debatable as it would make the same code do different things for >> e.g. vectors and sparse vectors. > > Iterating on the keys is more useful, in real-world programs. > If you mean because it's

Re: associative arrays: iteration is finally here

2009-10-29 Thread Nick Sabalausky
"Pelle Månsson" wrote in message news:hcaaro$15e...@digitalmars.com... > I think foreach should be consistent with opIn, that is, > if (foo in aa) { //it is in the aa. > foreach (f; aa) { // loop over each item in the aa > //I expect foo to show up in here, since it is "in" the aa. > } >

Re: associative arrays: iteration is finally here

2009-10-29 Thread Leandro Lucarella
Simen Kjaeraas, el 29 de octubre a las 22:06 me escribiste: > bearophile wrote: > > >In nothrow functions you can use a different method, like > >"discard" (or a similar name less intuitive than remove), that's > >like remove, but it doesn't throw and just returns false when the > >key was absent

Re: associative arrays: iteration is finally here

2009-10-29 Thread Simen Kjaeraas
bearophile wrote: In nothrow functions you can use a different method, like "discard" (or a similar name less intuitive than remove), that's like remove, but it doesn't throw and just returns false when the key was absent. The idea is to use the safer method by default and the less safe one

Re: associative arrays: iteration is finally here

2009-10-29 Thread bearophile
KennyTM~: > (Moreover, having .remove() to throw means you can't delete any > dictionary items in nothrow functions. Sure you can silent it with > try/catch but that's expensive.) In nothrow functions you can use a different method, like "discard" (or a similar name less intuitive than remove)

Re: associative arrays: iteration is finally here

2009-10-29 Thread Leandro Lucarella
Andrei Alexandrescu, el 29 de octubre a las 13:26 me escribiste: > Leandro Lucarella wrote: > >Andrei Alexandrescu, el 29 de octubre a las 12:33 me escribiste: > >>Bill Baxter wrote: > I think bool remove(key) is better than all other designs suggested so > far. > >>>I agree with the folks

Re: associative arrays: iteration is finally here

2009-10-29 Thread Leandro Lucarella
Bill Baxter, el 29 de octubre a las 11:31 me escribiste: > On Thu, Oct 29, 2009 at 11:16 AM, Leandro Lucarella wrote: > >> that's the overwhelmingly common case though, and if it's, say, > >> about 50/50, then it's much more sensible to have a non-throwing > >> primitive than a throwing one. And i

Re: associative arrays: iteration is finally here

2009-10-29 Thread rmcguire
Andrei Alexandrescu wrote: > rmcguire wrote: >> Wouldn't opIn be more useful if it returned a range starting with >> the element that was found? > > Thought about that, but it's hard to justify. Items aren't sorted in any > particular order, so you'd get pretty much a random bunch of stuff. >

Re: associative arrays: iteration is finally here

2009-10-29 Thread Leandro Lucarella
KennyTM~, el 30 de octubre a las 02:55 me escribiste: > On Oct 30, 09 01:14, bearophile wrote: > >KennyTM~: > > > >>Um what? aa["theKey"] = 1 doesn't fail, why should aa.remove("theKey") > >>be special? > > > >That's a different situation. > >You probably meant to say: If aa["theKey"]++; doesn't fa

Re: associative arrays: iteration is finally here

2009-10-29 Thread Andrei Alexandrescu
rmcguire wrote: Wouldn't opIn be more useful if it returned a range starting with the element that was found? Thought about that, but it's hard to justify. Items aren't sorted in any particular order, so you'd get pretty much a random bunch of stuff. Andrei

Re: associative arrays: iteration is finally here

2009-10-29 Thread KennyTM~
On Oct 30, 09 01:14, bearophile wrote: KennyTM~: Um what? aa["theKey"] = 1 doesn't fail, why should aa.remove("theKey") be special? That's a different situation. You probably meant to say: If aa["theKey"]++; doesn't fail, why should aa.remove("theKey") be special? void discard(K,V)(ref V[

Re: associative arrays: iteration is finally here

2009-10-29 Thread rmcguire
Andrei Alexandrescu wrote: > Denis Koroskin wrote: >> On Wed, 28 Oct 2009 17:22:00 +0300, Andrei Alexandrescu >> wrote: >> >>> Walter has magically converted his work on T[new] into work on making >>> associative arrays true templates defined in druntime and not >>> considered very special

Re: associative arrays: iteration is finally here

2009-10-29 Thread Bill Baxter
On Thu, Oct 29, 2009 at 11:16 AM, Leandro Lucarella wrote: > Andrei Alexandrescu, el 29 de octubre a las 12:33 me escribiste: >> Bill Baxter wrote: >> >>I think bool remove(key) is better than all other designs suggested so far. >> > >> >I agree with the folks who say it's error-prone.  I can just

Re: associative arrays: iteration is finally here

2009-10-29 Thread Andrei Alexandrescu
Leandro Lucarella wrote: Andrei Alexandrescu, el 29 de octubre a las 12:33 me escribiste: Bill Baxter wrote: I think bool remove(key) is better than all other designs suggested so far. I agree with the folks who say it's error-prone. I can just see myself now removing a key I know is in the d

Re: associative arrays: iteration is finally here

2009-10-29 Thread Bill Baxter
On Thu, Oct 29, 2009 at 10:33 AM, Andrei Alexandrescu wrote: > Bill Baxter wrote: >> >> On Thu, Oct 29, 2009 at 8:39 AM, Andrei Alexandrescu >> wrote: >>> >>> Leandro Lucarella wrote: Andrei Alexandrescu, el 28 de octubre a las 20:29 me escribiste: >>> >>> Your test looks someth

Re: associative arrays: iteration is finally here

2009-10-29 Thread Leandro Lucarella
Andrei Alexandrescu, el 29 de octubre a las 12:33 me escribiste: > Bill Baxter wrote: > >>I think bool remove(key) is better than all other designs suggested so far. > > > >I agree with the folks who say it's error-prone. I can just see > >myself now removing a key I know is in the dictionary and

Re: associative arrays: iteration is finally here

2009-10-29 Thread Andrei Alexandrescu
Bill Baxter wrote: On Thu, Oct 29, 2009 at 8:39 AM, Andrei Alexandrescu wrote: Leandro Lucarella wrote: Andrei Alexandrescu, el 28 de octubre a las 20:29 me escribiste: Your test looks something up and then removes it. Andrei Well, my extended test case looks something up, manipulates the

Re: associative arrays: iteration is finally here

2009-10-29 Thread Bill Baxter
On Thu, Oct 29, 2009 at 9:57 AM, KennyTM~ wrote: > On Oct 29, 09 23:59, Bill Baxter wrote: >> >> On Thu, Oct 29, 2009 at 8:39 AM, Andrei Alexandrescu >>  wrote: >>> >>> Leandro Lucarella wrote: Andrei Alexandrescu, el 28 de octubre a las 20:29 me escribiste: >>> >>> Your test lo

Re: associative arrays: iteration is finally here

2009-10-29 Thread bearophile
KennyTM~: > Um what? aa["theKey"] = 1 doesn't fail, why should aa.remove("theKey") > be special? That's a different situation. You probably meant to say: If aa["theKey"]++; doesn't fail, why should aa.remove("theKey") be special? > void discard(K,V)(ref V[K] aa, in K key) { >if (!aa.remov

Re: associative arrays: iteration is finally here

2009-10-29 Thread KennyTM~
On Oct 29, 09 23:59, Bill Baxter wrote: On Thu, Oct 29, 2009 at 8:39 AM, Andrei Alexandrescu wrote: Leandro Lucarella wrote: Andrei Alexandrescu, el 28 de octubre a las 20:29 me escribiste: Your test looks something up and then removes it. Andrei Well, my extended test case looks somet

Re: associative arrays: iteration is finally here

2009-10-29 Thread Kagamin
Andrei Alexandrescu Wrote: > Two other iterations are possible: by key and by value (in those cases > iter.front just returns a key or a value). Well, AA already has properties keys and values and you can already iterate over them. I think, it's ok to restrict to opApply(int delegate(ref KeyTyp

Re: associative arrays: iteration is finally here

2009-10-29 Thread Bill Baxter
On Thu, Oct 29, 2009 at 8:39 AM, Andrei Alexandrescu wrote: > Leandro Lucarella wrote: >> >> Andrei Alexandrescu, el 28 de octubre a las 20:29 me escribiste: > > Your test looks something up and then removes it. > > > Andrei Well, my extended test case looks something

Re: associative arrays: iteration is finally here

2009-10-29 Thread Andrei Alexandrescu
Leandro Lucarella wrote: Andrei Alexandrescu, el 28 de octubre a las 20:29 me escribiste: Your test looks something up and then removes it. Andrei Well, my extended test case looks something up, manipulates the found value, and then possibly removes it. Ok, I understand your points, thanks f

Re: associative arrays: iteration is finally here

2009-10-29 Thread Leandro Lucarella
Andrei Alexandrescu, el 28 de octubre a las 20:29 me escribiste: > >>Your test looks something up and then removes it. > >> > >> > >>Andrei > > > >Well, my extended test case looks something up, manipulates the > >found value, and then possibly removes it. > > Ok, I understand your points, thanks

Re: associative arrays: iteration is finally here

2009-10-29 Thread bearophile
bearophile: > Pelle Månsson: > > I agree with this. I usually want exceptions. > > A problem with this is that currently exceptions are very slow in D compiled > with DMD (something like up to 11 times slower than Java exceptions, about > 2-4 times slower than Python exceptions. I have a benchm

Re: associative arrays: iteration is finally here

2009-10-29 Thread bearophile
Pelle Månsson: > I agree with this. I usually want exceptions. A problem with this is that currently exceptions are very slow in D compiled with DMD (something like up to 11 times slower than Java exceptions, about 2-4 times slower than Python exceptions. I have a benchmark for this on my site).

Re: associative arrays: iteration is finally here

2009-10-29 Thread Steven Schveighoffer
On Wed, 28 Oct 2009 10:22:00 -0400, Andrei Alexandrescu wrote: Walter has magically converted his work on T[new] into work on making associative arrays true templates defined in druntime and not considered very special by the compiler. This is very exciting because it opens up or simplif

Re: associative arrays: iteration is finally here

2009-10-29 Thread Steven Schveighoffer
On Wed, 28 Oct 2009 20:08:34 -0400, Andrei Alexandrescu wrote: Denis Koroskin wrote: On Wed, 28 Oct 2009 23:18:08 +0300, Andrei Alexandrescu wrote: I'd also like you to add a few things in an AA interface. First, opIn should not return a pointer to Value, but a pointer to a pair of K

Re: associative arrays: iteration is finally here

2009-10-29 Thread Pelle Månsson
bearophile wrote: Andrei Alexandrescu: I'll make aa.remove(key) always work and return a bool that tells you whether there was a mapping or not. I think that's a small design mistake. In a high level language you want things to not fail silently. You want them to fail in an explicit way beca

Re: associative arrays: iteration is finally here

2009-10-29 Thread bearophile
Andrei Alexandrescu: > I'll make aa.remove(key) always work and return a bool that tells you > whether there was a mapping or not. I think that's a small design mistake. In a high level language you want things to not fail silently. You want them to fail in an explicit way because programmers

Re: associative arrays: iteration is finally here

2009-10-28 Thread Andrei Alexandrescu
Denis Koroskin wrote: On Thu, 29 Oct 2009 03:08:34 +0300, Andrei Alexandrescu wrote: Denis Koroskin wrote: On Wed, 28 Oct 2009 23:18:08 +0300, Andrei Alexandrescu wrote: I'd also like you to add a few things in an AA interface. First, opIn should not return a pointer to Value, but a poi

Re: associative arrays: iteration is finally here

2009-10-28 Thread Denis Koroskin
On Thu, 29 Oct 2009 03:08:34 +0300, Andrei Alexandrescu wrote: Denis Koroskin wrote: On Wed, 28 Oct 2009 23:18:08 +0300, Andrei Alexandrescu wrote: I'd also like you to add a few things in an AA interface. First, opIn should not return a pointer to Value, but a pointer to a pair of K

Re: associative arrays: iteration is finally here

2009-10-28 Thread Andrei Alexandrescu
Denis Koroskin wrote: On Wed, 28 Oct 2009 23:18:08 +0300, Andrei Alexandrescu wrote: I'd also like you to add a few things in an AA interface. First, opIn should not return a pointer to Value, but a pointer to a pair of Key and Value, if possible (i.e. if this change won't sacrifice perfor

Re: associative arrays: iteration is finally here

2009-10-28 Thread Andrei Alexandrescu
Lars T. Kyllingstad wrote: Andrei Alexandrescu wrote: dsimcha wrote: == Quote from Andrei Alexandrescu (seewebsiteforem...@erdani.org)'s article Walter has magically converted his work on T[new] into work on making associative arrays true templates defined in druntime and not considered very

Re: associative arrays: iteration is finally here

2009-10-28 Thread Lars T. Kyllingstad
Andrei Alexandrescu wrote: dsimcha wrote: == Quote from Andrei Alexandrescu (seewebsiteforem...@erdani.org)'s article Walter has magically converted his work on T[new] into work on making associative arrays true templates defined in druntime and not considered very special by the compiler. This

Re: associative arrays: iteration is finally here

2009-10-28 Thread Pelle Månsson
Lars T. Kyllingstad wrote: Pelle Månsson wrote: Lars T. Kyllingstad wrote: Pelle Månsson wrote: Andrei Alexandrescu wrote: Pelle Månsson wrote: Also, foreach with a single variable should default to keys, in my opinion. That is debatable as it would make the same code do different things

Re: associative arrays: iteration is finally here

2009-10-28 Thread Denis Koroskin
On Wed, 28 Oct 2009 23:18:08 +0300, Andrei Alexandrescu wrote: I'd also like you to add a few things in an AA interface. First, opIn should not return a pointer to Value, but a pointer to a pair of Key and Value, if possible (i.e. if this change won't sacrifice performance). I'm coy ab

Re: associative arrays: iteration is finally here

2009-10-28 Thread Lars T. Kyllingstad
Pelle Månsson wrote: Lars T. Kyllingstad wrote: Pelle Månsson wrote: Andrei Alexandrescu wrote: Pelle Månsson wrote: Also, foreach with a single variable should default to keys, in my opinion. That is debatable as it would make the same code do different things for e.g. vectors and sparse

Re: associative arrays: iteration is finally here

2009-10-28 Thread Andrei Alexandrescu
Denis Koroskin wrote: On Wed, 28 Oct 2009 17:22:00 +0300, Andrei Alexandrescu wrote: Walter has magically converted his work on T[new] into work on making associative arrays true templates defined in druntime and not considered very special by the compiler. Wow, this is outstanding! (I h

Re: associative arrays: iteration is finally here

2009-10-28 Thread Pelle Månsson
Lars T. Kyllingstad wrote: Pelle Månsson wrote: Andrei Alexandrescu wrote: Pelle Månsson wrote: Also, foreach with a single variable should default to keys, in my opinion. That is debatable as it would make the same code do different things for e.g. vectors and sparse vectors. Andrei D

Re: associative arrays: iteration is finally here

2009-10-28 Thread Pelle Månsson
Robert Jacques wrote: On Wed, 28 Oct 2009 15:06:34 -0400, Denis Koroskin <2kor...@gmail.com> wrote: On Wed, 28 Oct 2009 17:22:00 +0300, Andrei Alexandrescu wrote: Walter has magically converted his work on T[new] into work on making associative arrays true templates defined in druntime and

Re: associative arrays: iteration is finally here

2009-10-28 Thread Pelle Månsson
Denis Koroskin wrote: On Wed, 28 Oct 2009 17:22:00 +0300, Andrei Alexandrescu wrote: Walter has magically converted his work on T[new] into work on making associative arrays true templates defined in druntime and not considered very special by the compiler. Wow, this is outstanding! (I h

Re: associative arrays: iteration is finally here

2009-10-28 Thread Denis Koroskin
On Wed, 28 Oct 2009 22:24:46 +0300, Robert Jacques wrote: On Wed, 28 Oct 2009 15:06:34 -0400, Denis Koroskin <2kor...@gmail.com> wrote: On Wed, 28 Oct 2009 17:22:00 +0300, Andrei Alexandrescu wrote: Walter has magically converted his work on T[new] into work on making associative ar

Re: associative arrays: iteration is finally here

2009-10-28 Thread Robert Jacques
On Wed, 28 Oct 2009 15:06:34 -0400, Denis Koroskin <2kor...@gmail.com> wrote: On Wed, 28 Oct 2009 17:22:00 +0300, Andrei Alexandrescu wrote: Walter has magically converted his work on T[new] into work on making associative arrays true templates defined in druntime and not considered ve

Re: associative arrays: iteration is finally here

2009-10-28 Thread Denis Koroskin
On Wed, 28 Oct 2009 17:22:00 +0300, Andrei Alexandrescu wrote: Walter has magically converted his work on T[new] into work on making associative arrays true templates defined in druntime and not considered very special by the compiler. Wow, this is outstanding! (I hope it didn't have a

Re: associative arrays: iteration is finally here

2009-10-28 Thread bearophile
Andrei Alexandrescu: > That is debatable as it would make the same code do different things for > e.g. vectors and sparse vectors. Iterating on the keys is more useful, in real-world programs. Regarding the names: - "keys", "values" return lazy iterators. "keys" returns a set-like object that

Re: associative arrays: iteration is finally here

2009-10-28 Thread Lars T. Kyllingstad
Pelle Månsson wrote: Andrei Alexandrescu wrote: Pelle Månsson wrote: Also, foreach with a single variable should default to keys, in my opinion. That is debatable as it would make the same code do different things for e.g. vectors and sparse vectors. Andrei Debatable indeed, but I find

Re: associative arrays: iteration is finally here

2009-10-28 Thread Andrei Alexandrescu
yigal chripun wrote: Andrei Alexandrescu Wrote: Walter has magically converted his work on T[new] into work on making associative arrays true templates defined in druntime and not considered very special by the compiler. This is very exciting because it opens up or simplifies a number of po

Re: associative arrays: iteration is finally here

2009-10-28 Thread Leandro Lucarella
Pelle Månsson, el 28 de octubre a las 15:48 me escribiste: > Andrei Alexandrescu wrote: > >Walter has magically converted his work on T[new] into work on > >making associative arrays true templates defined in druntime and > >not considered very special by the compiler. > > > >This is very exciting

Re: associative arrays: iteration is finally here

2009-10-28 Thread yigal chripun
Andrei Alexandrescu Wrote: > Walter has magically converted his work on T[new] into work on making > associative arrays true templates defined in druntime and not considered > very special by the compiler. > > This is very exciting because it opens up or simplifies a number of > possibilities.

Re: associative arrays: iteration is finally here

2009-10-28 Thread Andrei Alexandrescu
dsimcha wrote: == Quote from Andrei Alexandrescu (seewebsiteforem...@erdani.org)'s article Walter has magically converted his work on T[new] into work on making associative arrays true templates defined in druntime and not considered very special by the compiler. This is very exciting because it

Re: associative arrays: iteration is finally here

2009-10-28 Thread Max Samukha
On Wed, 28 Oct 2009 09:22:00 -0500, Andrei Alexandrescu wrote: >Walter has magically converted his work on T[new] into work on making >associative arrays true templates defined in druntime and not considered >very special by the compiler. > >This is very exciting because it opens up or simplifi

Re: associative arrays: iteration is finally here

2009-10-28 Thread dsimcha
== Quote from Andrei Alexandrescu (seewebsiteforem...@erdani.org)'s article > Walter has magically converted his work on T[new] into work on making > associative arrays true templates defined in druntime and not considered > very special by the compiler. > This is very exciting because it opens up

Re: associative arrays: iteration is finally here

2009-10-28 Thread Pelle Månsson
Andrei Alexandrescu wrote: Pelle Månsson wrote: Andrei Alexandrescu wrote: Walter has magically converted his work on T[new] into work on making associative arrays true templates defined in druntime and not considered very special by the compiler. This is very exciting because it opens up or

Re: associative arrays: iteration is finally here

2009-10-28 Thread Justin Johansson
Andrei Alexandrescu Wrote: > Walter has magically converted his work on T[new] into work on making > associative arrays true templates defined in druntime and not considered > very special by the compiler. > > This is very exciting because it opens up or simplifies a number of > possibilities.

Re: associative arrays: iteration is finally here

2009-10-28 Thread Andrei Alexandrescu
Pelle Månsson wrote: Andrei Alexandrescu wrote: Walter has magically converted his work on T[new] into work on making associative arrays true templates defined in druntime and not considered very special by the compiler. This is very exciting because it opens up or simplifies a number of pos

Re: associative arrays: iteration is finally here

2009-10-28 Thread Pelle Månsson
Andrei Alexandrescu wrote: Walter has magically converted his work on T[new] into work on making associative arrays true templates defined in druntime and not considered very special by the compiler. This is very exciting because it opens up or simplifies a number of possibilities. One is tha

associative arrays: iteration is finally here

2009-10-28 Thread Andrei Alexandrescu
Walter has magically converted his work on T[new] into work on making associative arrays true templates defined in druntime and not considered very special by the compiler. This is very exciting because it opens up or simplifies a number of possibilities. One is that of implementing true itera