Discussion Thread: DIP 1039--Static Arrays with Inferred Length--Community Review Round 1

Luhrel lucien.perregaux at gmail.com
Mon Jan 11 20:25:14 UTC 2021


On Monday, 11 January 2021 at 12:32:42 UTC, Nick Treleaven wrote:
> On Friday, 8 January 2021 at 14:07:29 UTC, Luhrel wrote:
>>> Example a3 is straightforward the primary use case for 
>>> staticArray:
>>>     auto a3 = [1,2,3].staticArray;
>>
>> I really don't like the `.staticArray` because it's 
>> non-esthetic. I don't know if it's really argument, mainly 
>> because it's very personal.
>
> The worst thing about it is you have to import std.array, so 
> probably people won't bother scrolling to the top to add the 
> import and losing/bookmarking their place, and will just count 
> the items themselves. When it was originally proposed, it was 
> in object.d.

Yep, I introduced this DIP because I had to count the number of 
elements in my array (I'm lazy).

>
> I think if the DIP proposed a literal syntax instead of a new 
> variable declaration syntax, it would be much less of a burden 
> to the compiler. I think we don't have any partial (variable) 
> type inference syntax ATM.

I don't think that will be complicated to implement, the compiler 
already says "mismatched array lengths, 2 and 1".

>
>> Correct. I'll rewrite this example.
>> There should be a type conversion:
>>
>> ```
>> int[2] bar() { return [1,2]; }
>> long[$] a6 = bar();  // implicit conversion
>> static assert(is(typeof(a6) == long[2]));
>> ```
>
> Error: cannot implicitly convert expression `bar()` of type 
> `int[2]` to `long[]`

Meh, gonna review my examples.


```
int[] bar() { return [1,2]; }
int[$] a6 = bar();  // conversion from int[] to int[2]
static assert(is(typeof(a6) == int[2]));
```
When manually replacing $ by 2, it now works as excepted.



More information about the Digitalmars-d-announce mailing list