[:] as empty associative array literal, plus warning for null

TommiT tommitissari at hotmail.com
Wed Jul 3 10:53:44 PDT 2013


On Wednesday, 3 July 2013 at 14:33:02 UTC, bearophile wrote:
> [..]

I think it's a good idea to have [:] literal for associative 
arrays since there's [] literal for dynamic arrays.

But I would expect [] to mean "empty dynamic array", not null. 
And the same for [:]. This is how I'd expect things to work:

int[] nullArray;
assert(nullArray is null);

int[] emptyArray = [];
assert(emptyArray !is null);

int[string] nullAA;
assert(nullAA is null);

int[string] emptyAA = [:];
assert(emptyAA !is null);

Reasoning by extrapolation:
int[] arr = [1, 2, 3]; // Array of 3 ints
int[] arr = [1, 2]; // Array of 2 ints
int[] arr = [1]; // Array of 1 ints
int[] arr = []; // Array of 0 ints (not null)


More information about the Digitalmars-d mailing list