The Dot Access Operator : for access into any sequence type


#1

The Dot Access Operator : Uniform Syntax : for access into any sequence type :

array vs tuple syntaxes : in realm of consistency

let a: [u16; 4] = [ 1, 2, 3, 4]; let a = [ 1, 2, 3, 4];

// bracket syntax for array : println!( “printing a fields {} , {}”, a[0], a[3]};

// dot syntax for array : why not? println!( “printing a fields {} , {}”, a.0, a.3}; // array is a strict subset of type of tuple. // it is a single, tuple can be a single as well

let b: (u16, u16, u16, u16) = (1, 2, 3, 4); let b = (1, 2, 3, 4);

// repetition syntax : why not? let b: (u16; 4) = (1, 2, 3, 4); // as long as the type is the same, the compact syntax works fine. // (u16; 4) means four slots of u16.


#2

The difference between tuple indexing and array indexing is that array indexes can be computed at runtime, can potentially be out of bounds, and can be arbitrarily complex expressions while tuple indexing iirc is limited to integer literals. Given that, I don’t see why dot syntax for arrays would be beneficial.


#3
println!("printing a fields {} , {}", a.0, a.3};

I’ll be honest: I kind of like that, because it can give errors at runtime compile time

as long as the type is the same, the compact syntax works fine. (u16; 4) means four slots of u16.

…eh. I would rather see fixed-size array patterns get stabilized:

let [a, b, c, d] = [2i32, 3i32, 4i32, 6i32];

so that I can stop having to use (i32, i32, i32, i32) as an ergonomical workaround. Rust’s current story for working with small, fixed-size sets of homogenous data type is, to be quite honest, kinda lame.