On Wednesday, 22 October 2025 at 20:52:36 UTC, monkyyy wrote:
>float[10] b = [0:42, 5: 3.14, $:13.37];//[0,13.37,13.37,13.37,13.37,3.14,13.37...
This makes no sense to me, The first element in the array at index zero should be 42, not zero? Is this intentional or a typo?
I really do not like this syntax $:13.37 because its inconsistent with slicing. $ is the length of the array, Its nonsensical it looks like your trying to write 13.37 into the 11th element of a 10 long array.
import std : writeln;
void main()
{
string foo = "hello";
// This will be an out of bounds error.
writeln(foo[$]);
// This should also be an out of bounds error
// Otherwise your adding a one off special meaning for `$`.
float[10] bar = [$:4.14];
// This will slice out the full array & print hello.
writeln(foo[0..$]);
// This will write 4.14 into the full array.
// If you know how slicing works this should be intuitive.
float[10] baz = [0..$:4.14];
}
Permalink
Reply