This is my first post to the dev mailing list, so please take with a
grain of salt.

Three things:

First, regarding syntax, couldn't we just leverage the existing
semantics an allocated vector implies mutability, for which Rust
already expresses via 'mut'

Could one simply just:

let mut x = [1,2,3,4,5]    // alloca'd
let x = [1,2,3,4,5]           // constant mem

and the rest:
let x = @[p,q,r]              //heap-resident shared, type [int/@]
let x = ~[p,q,r]               // -- heap-resident unique, type [int/~]

In the first case, this obviously means that we're inferring the
storage type of the vector based on the binding, I'm not sure if this
is easily accomplished.

In my experience, looking at my code,  when I statically initialize a
list/vector, I generally intend it to be constant.
If I don't initialize, then the intent is obvious.
So the default case for static initialization is const mem, then I see
no problem with :
  1. having to provide special syntax which indicates that I want
dynamic mem for the statically init'd vector.
  2.  Some mechanism for copying my const vector to dynamic allocation
if I change my mind later.

With regards to fixed sized arrays and slices I mostly agree with
Sebastian Sylvan,  I would like the default operations on
arrays/vectors be slices.
If we need to "copy-on-write", it can be explicit. The compiler will
detect that I am about to touch the vector in improper ways and error.

e.g. let x = [1,2,3,4,5]
x[5] = 6;                      // Errors for one of two reasons,  the
handle x to the vector is const, and the vector itself is const.

so I have to
let y = @clone(x)
or
let y = mut x              //  these would create a copy of the vector
pointed to by x on the heap and creates y as slice that references the
new vector.

The way I prefer to view slices are as some sort of first-class
thick-pointer which contains
1. A pointer to the beginning vector in mem
2. The size of the slice
3. The offset at which it begins.

I am not familiar enough with the implementation of Rust to comment on
the feasibility of this, but I have this handy bucket of shed paint
here so I had to chime in.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to