chapel-lang/chapel — pull request #128 by benharsh (2014-08-08 18:25:13+00:00)
Title: Support for adding to an associative array's domain via the array itself

This code allows for one to implicitly add to an associative array's domain via that array. This makes associative arrays a little more pleasant to work with.

Before:

myDom += newKey;
myArr[newKey] = foo;

After:

myArr[newKey] = foo; // newKey added to backing domain if not present.

An important restriction is that the array and domain must share a 1:1 relationship. More simply, the domain must only be backing one array. This motivation for this restriction is that it may be surprising that other arrays' index sets are modified when it appears that we are only modifying one array. If this restriction is violated, the program will halt.

An 'out of bounds' halt will still occur if attempting to read from a bad index:

Before and after:

writeln(myArr[badKey]); // if 'badKey' is not in myArr's index set, the usual error will be encountered.