When are associative arrays meant to throw a RangeError?

Ben Davis entheh at cantab.net
Sat Feb 18 15:08:18 PST 2012


On 18/02/2012 22:57, Andrej Mitrovic wrote:
> Are you familiar with cases where you want regular arrays to return
> Type.init when you go out of bounds?

The front page says D isn't meant to be an orthogonal language :P

If you want orthogonality, then associative arrays will have to work 
something like this:

int[string] stuff;

stuff.addKey("a");
stuff.addKey("b");
stuff.addKey("d");
stuff.addKey("e");

stuff["a"]=0;
stuff["b"]=1;
stuff["c"]=2; //error
writefln("%s",stuff["d"]);
writefln("%s",stuff["e"]);
writefln("%s",stuff["f"]); //error

Do you want to do that?


More information about the Digitalmars-d mailing list