On 11/8/13 7:47 AM, Diggory Hardy wrote:
What's wrong with sticking with convention here? E.g. C++'s `string` and
`vector<T>` are objects containing two or three pointers. D's arrays and
`string` act the same way. Even C's dynamic arrays (`int x[]`) can be thought
of the same way (if one avoids thinking of them as pointers).

Because:

* We need slices in the language. They're important for soundness.

* We need dynamically sized types in the language in order to be sound around first-class trait objects.

* Given that we need slices, and we need dynamically-sized types, we can avoid introducing more concepts in the language by treating slices as just a special case of a dynamically-sized type. That is, a slice is nothing more than *a pointer to a dynamically-sized type*.

* The pointer sigil is notated `&`, and the dynamically-sized type is `[int]`. So the resulting notation is `&[int]`.

You can see slices as just pointers with a length attached; i.e. a pointer to multiple contiguous values. In fact, Cyclone called them "fat pointers" instead of "slices". In Cyclone, you wrote a slice as `int *fat`. (Notice the similarity to `&[int]`.)

Note that not all of this is implemented today, which is leading to some of the confusion in this thread. Felix Klock is currently working on it.

Patrick

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to