non-aa-initializer?

Salih Dincer salihdb at hotmail.com
Fri Dec 2 19:36:10 UTC 2022


On Friday, 2 December 2022 at 18:26:36 UTC, Steven Schveighoffer 
wrote:
> This is not an associative array initializer:
>
> ```d
> ['A' : ['B': 0]]
> ```
>
> Yet, this is:
>
> ```d
> (['A' : ['B': 0]])
> ```

This looks like the nested objects I use in JSON and doesn't need 
parentheses because it's built with JSON.  For example, without 
the parentheses, the first one will not compile, but will compile 
when the individual objects are created:

```d
void main()
{
   alias letter = int[char];/*
   letter[string] letters = [
     "Upper" : ['A': 65],
     "Lower" : ['a': 97]
   ]; //* not compile */

   letter[string] letters = ([
     "Upper" : ['A': 65],
     "Lower" : ['a': 97]
   ]); // okay

   letter[]  up = [['A': 65], ['B': 66], ['C': 67]];
   letter[] low = [['a': 97], ['b': 98], ['c': 99]];

   letter[string] lets = [
     "Upper" : up[0],
     "Lower" : low[0]
   ]; // okay

   assert(lets == letters);
}
```
SDB at 79


More information about the Digitalmars-d mailing list