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

Timon Gehr timon.gehr at gmx.ch
Wed Jul 3 12:55:29 PDT 2013


On 07/03/2013 07:53 PM, TommiT wrote:
> 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)

+1.


More information about the Digitalmars-d mailing list