associative arrays

Ali Çehreli acehreli at
Sat Jan 7 15:06:30 PST 2012

On 01/07/2012 02:11 PM, RenatoL wrote:
 > Very quick question
 > import std.stdio;
 > void main()
 > {
 > 	auto arr1 = ["uno":1, "due":2, "tre":3];
 > 	arr1.remove("xxx");
 > }
 > also in this case the compiler does not say anything and the
 > program goes out silently ... why? Would not it be better if an
 > exception was raised?

I think that could be a valid design choice. On the other hand, since 
what is required is to remove the element, it is not really an error if 
the object is already missing. The requirement is met.

 > After all if i write:
 > writeln(arr1["xxx"]);
 > runtime expresses its disappointment...

You get the exception more simply by this:

     auto e = arr1["xxx"];

But that's understandable because the [] operator is supposed to provide 
access to a usable object. Since there is no general concept of a null 
object, there is no object to provide access to, so there is nothing 
else to do but to throw.


More information about the Digitalmars-d-learn mailing list