When are associative arrays meant to throw a RangeError?

Ben Davis entheh at cantab.net
Sat Feb 18 03:39:53 PST 2012


Starting with magic initialisation then...

Is it vital that e[nonexistentKey] throw a RangeError, or could it just 
always return the type's default value if the key is absent?

If you change that, then you can make assignment evaluate the RHS fully 
before even creating the LHS entry, and you won't in the process break 
the common case where people want to go

count[key]++;
or
array[key]~=element;

without worrying about whether it's the first time for that key or not.

Users who want to know if the entry is there could then use 'in' (once 
it's fixed).

On 18/02/2012 04:13, Daniel Murphy wrote:
> Yeah, but that requires a design that fixes everything, including literals,
> template arg deduction, magic initialization etc.
>
> "Jonathan M Davis"<jmdavisProg at gmx.com>  wrote in message
> news:mailman.514.1329537168.20196.digitalmars-d at puremagic.com...
>> On Saturday, February 18, 2012 14:46:21 Daniel Murphy wrote:
>>> Yes, that's the issue I'm talking about.  In this case no comments means
>>> no
>>> disagreements.  Unfortunately it requires changes to the AA api/codegen
>>> to
>>> fix, so it will probably be around until we move AAs completely into
>>> druntime.
>>
>> Which should probably be sorted out sooner rather than later given all of
>> the
>> bugs involved.
>>
>> - Jonathan M Davis
>
>



More information about the Digitalmars-d mailing list