From 14e245bd47d3ac1a981d50a6f752aa27cca7d85e Mon Sep 17 00:00:00 2001 From: LemmingAvalanche Date: Fri, 4 Jul 2014 13:19:42 +0200 Subject: [PATCH] Note naming convention of lists (xs, ys, ...) People reading the tutorial may not be familiar with the convention of naming lists, vectors and the like as xs, ys, etc. Without some explanation of the reasoning behind it, it might come off as just throwaway non-descriptive names. Languages like Haskell gets flak from using short, non-descriptive names, while in reality, there are clear conventions and reasons for using certain terse variable names. I assumed that the convention came from a language like Haskell, so I tailored the explanation according to that. --- src/doc/tutorial.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/doc/tutorial.md b/src/doc/tutorial.md index 2a788d7e7934c..96b57f59cce61 100644 --- a/src/doc/tutorial.md +++ b/src/doc/tutorial.md @@ -1110,6 +1110,16 @@ let xs = Cons(1, box Cons(2, box Cons(3, box Nil))); let ys = xs; // copies `Cons(u32, pointer)` shallowly ~~~ +> *Note:* Names like `xs` and `ys` are a naming +> convention for collection-like data structures +> (like our `List`). These collections are given +> names appended with 's' to signify plurality, +> i.e. that the data structure stores multiple +> elements. For example, `xs` in this case can +> be read as "a list of ex-es", where "x" here +> are elements of type `u32`. + + Rust will consider a shallow copy of a type with a destructor like `List` to *move ownership* of the value. After a value has been moved, the source location cannot be used unless it is reinitialized.