Skip to content

Fix vector terminology in the manual. #17154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2014

Conversation

steveklabnik
Copy link
Member

fixes #17148

@nodakai
Copy link
Contributor

nodakai commented Sep 11, 2014

This update is not yet enough because the underlying semantics is not considered. For example,

+[Array](#vector,-array,-and-slice-types)-typed expressions can be indexed by writing a
 square-bracket-enclosed expression (the index) after them. When the

this sentence refers only to the array type among three related types. Now we know what [0i][0] means but don't know what vec![0i][0] means. I think you need to introduce a new term to group vector, array, and slice types which all accept the index notation.

Moreover, while the vector and slice types are covered in the API reference, the array type is not. So we don't know why [0i].len() compiles at all and what it means.

The (non-)relationship between [int, .. 1] and [int, .. 2] should also be expliciltly stated.

fn main() {
    let a: [int, .. 1] = [0i, 1i];
}

http://is.gd/O8EJGx

What are the differences between arrays and immutable Vec? The former can be allocated on the stack is not usually visible to a Rust programmer.

@huonw
Copy link
Member

huonw commented Sep 11, 2014

Note that this update is literally just correcting the name to the accepted conventions, it is doing nothing to the actual content.

Now we know what [0i][0] means but don't know what vec![0i][0] means

The meaning of this is implied by the trait impls of Vec; unlike array (and slice) expressions. I imagine we don't want to be talking about e.g. Bitv here (which also accepts [] indexing notation).

What are the differences between arrays and immutable Vec? The former can be allocated on the stack is not usually visible to a Rust programmer.

One is in the language (arrays) and one is entirely defined in libraries (Vec).

@steveklabnik
Copy link
Member Author

Arrays and slices are the only native types technically, Vec is a library type. We haven't decided, but the manual will probably be only the language spec, without libraries.

Also, while it's true that there's not more information, this is actually about just fixing it to not be broken. Eventually the manual is going to get a full overhaul, but now is not that time, and I'd rather not let the perfect be the enemy of the better.

@nodakai
Copy link
Contributor

nodakai commented Sep 11, 2014

@huonw My bad, I overlooked the fact that Vec implements Index.

I can indeed read vec.rs but I wanted you to clarify how the built-in array types are semantically different from Vec. Then we will understand array better; Vec + (array - Vec) = array, you know.

Incidentally, please note that good programming languages shouldn't force a programmer to distinguish built-in types and library types. Programmers praise Lisp and Smalltalk and badmouth Java partly because of that. My understanding is that the array type is unique in Rust that it is parametrized by its element type and its size (compare Rust traits with C++ templates which can also accept compile-time constant integers.) The official documents should do their best to minimize newcomers' surprise on that.

I hope this issue is regarded as a showstopper for 1.0.

@pcwalton
Copy link
Contributor

I am opposed to blocking 1.0 on this.

@bors bors closed this Sep 11, 2014
@bors bors merged commit faf14ae into rust-lang:master Sep 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Documents should clarify about arrays
6 participants