Inferring static array size

NotYouAgain NotYouAgain at gmail.com
Sun Apr 28 10:49:24 UTC 2024


On Sunday, 28 April 2024 at 10:17:06 UTC, ryuukk_ wrote:
>
> YES please, this is long overdue, there is no reason to not 
> have this
>
> However, i don't like the proposed syntax, it should be 1 
> character to type, and should not be a ugly one
>
> `_` should be enough

So my thinking behind [$_] is:

'$' is already a synonym for the length of the array.

e.g
  int[2] arr = [1,2];
  writeln(arr[0..arr.length]); // [1, 2]
  writeln(arr[0..$]); // [1, 2]

so with [$_] ... '$_' means 'array length' and '_' means.. please 
compiler fill in missing blank.

true, [_] can just as easily mean .. please compiler fill in the 
missing blank.

Frankly I don't mind either.

[_] is easier to type, but not as easy on the eye I think ;-)  
..looks kinda like a box in my ide.



More information about the dip.ideas mailing list