I'm testing the capability of rust to decide if I should convert to that as my goto language.
I have at this moment read the whole book from front to back and done some simple implementation to get accustom to the syntax and type system (not that big a deal comming from SML and F#)
I though have a implementation related question.
Why did they not make it possible to make allocation of an array dynamic? i.e. making it possible to give initiate an array with size n where n is computed at run time. I understand that this will lead to a minor runtime penalty, since we need to compute that size at runtime, but still this is a marginal runtime penalty.
Yes I know that there is the 'Vec' type, but this is resizable which can leads to even more runtime penalty, and give less clear intention of the code, when read by other programmers.
To sum it up why isn't it possible to do something like
fn darr(item : i32, n : i32) {
let arr = [item; n];
println!("sum is {}",arr.iter().sum());
}
it is possible to make a dynamic sized stack frame under the assumption that the size is given at runtime before allocation, with little overheath (calculation of the size).