More magical AA semantics

Jonathan M Davis jmdavisProg at gmx.com
Sat Jan 12 04:40:16 PST 2013


On Saturday, January 12, 2013 13:30:47 monarch_dodra wrote:
> On Saturday, 12 January 2013 at 12:05:30 UTC, Jonathan M Davis
> 
> wrote:
> > On Saturday, January 12, 2013 11:51:59 monarch_dodra wrote:
> >> I guess I can see it either way. My only gripe though is that:
> >> "a[0] = a[0] + 5;"
> >> 
> >> Could never work if AA's were a "true" library type. I think
> >> this
> >> is a problem, if the plan is to one day completely move AA's
> >> out
> >> of the compiler.
> >> 
> >> That, and for generic programming, it means my user written
> >> HashMap! will never be able to have AA's semantics.
> > 
> > But that should result in a RangeError. It's not something
> > that's supposed to
> > work. It's a bug. So, the fact that a library type couldn't
> > duplicate it is
> > irrelevant. The fact that it can't have a particular bug isn't
> > exactly a
> > problem.
> > 
> > - Jonathan M Davis
> 
> Oh... Right...
> 
> I guess I missread this thread (and 9rnsr's pull), and was lead
> to understand that we were going the road of accepting this.
> 
> Well, my bad than.

I don't know what he's doing in his pull, but I think that it's clear that it 
should be a RangeError, and I don't think that much of anyone in this thread 
is disputing that.

> What about "++a[0]" when there is no a[0]? Is this something that
> will throw or not?

Personally, I think that it should, but there's probably a good chance that it 
won't, because it's an lvalue. I don't know what will happen with that though. 
There are a lot of bugs right now related elements being inserted into AAs 
when they shouldn't be, so I really don't know how much relation the current 
behavior will have with the behavior that AAs will ultimately have.

> As well, what about
> //----
> immutable(int)[int] aa;
> aa[0] = 5;
> //----
> This should work, right?

That should definitely work. That's how you add elements to AA. My gripe with 
something like ++a[0] working when there's no a[0] is that you'd be adding to 
an element that doesn't exist yet.

- Jonathan M Davis


More information about the Digitalmars-d mailing list