Pre-RFC: Array expansion syntax

This reminds me of tuple splatting, such as Splats and tuples - Crystal -- should it work for that as well? Is there anything specific about arrays here? What about mixing? Can I convert a let p = (1, 2); into an array with [...p]?

It's not at all clear to me that a breaking change here is worth it. Why not just use three dots, say, like C++ parameter pack expansion? (Oh, and like in javascript, you mention later.)

The FRU parallel here doesn't feel that strong to me, since FRU is the same type, but this almost never would be (it wouldn't be illegal, but [..a] would just be a). In fact, the FRU parallel might have me expect that [1, ..[0;3]] is [1, 0, 0] because it only uses the rest of the elements. (If you think of an array as a tuple struct with homogeneous fields and repr(C), then ['a', ..['b';3]] is Array3 { 0: 'a', ..Array3('b', 'b', 'b') } => Array3('a', 'b', 'b'), not something producing Array4.)

I would expect const fn concat_arrays<T, N: usize, M: usize>(a: [T; N], b: [T; M]) -> [T; {N+M}] to work eventually, which would not require that the user specify the length of the resulting array.

Now, that doesn't necessarily mean this is a bad feature, but I'm not convinced by this part of the motivation.

5 Likes