Skip to content

Commit 14e245b

Browse files
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.
1 parent 5012b85 commit 14e245b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/doc/tutorial.md

+10
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,16 @@ let xs = Cons(1, box Cons(2, box Cons(3, box Nil)));
11101110
let ys = xs; // copies `Cons(u32, pointer)` shallowly
11111111
~~~
11121112

1113+
> *Note:* Names like `xs` and `ys` are a naming
1114+
> convention for collection-like data structures
1115+
> (like our `List`). These collections are given
1116+
> names appended with 's' to signify plurality,
1117+
> i.e. that the data structure stores multiple
1118+
> elements. For example, `xs` in this case can
1119+
> be read as "a list of ex-es", where "x" here
1120+
> are elements of type `u32`.
1121+
1122+
11131123
Rust will consider a shallow copy of a type with a destructor like `List` to
11141124
*move ownership* of the value. After a value has been moved, the source
11151125
location cannot be used unless it is reinitialized.

0 commit comments

Comments
 (0)