From 009852b456e75f3cefcc3535f0f77216fc9471e0 Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Sat, 3 Jun 2017 13:59:59 +0800 Subject: [PATCH 1/9] Take back the glossory items from the first edition of the book. Add some small editorial changes. --- src/SUMMARY.md | 2 ++ src/glossory.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/glossory.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 02cc90d3ce171..a06caa72f65fc 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -58,3 +58,5 @@ [Appendix: Influences](influences.md) [Appendix: As-yet-undocumented Features](undocumented.md) + +[Appendix: Glossory](glossory.md) diff --git a/src/glossory.md b/src/glossory.md new file mode 100644 index 0000000000000..45e37b588ab28 --- /dev/null +++ b/src/glossory.md @@ -0,0 +1,64 @@ +# Glossary + +### Abstract Syntax Tree + +‘Abstract syntax tree’, or ‘AST’. This tree is an intermediate representation of +the structure of your program when the compiler is compiling your program. + +For example, `2 + 3` can be turned into a tree: + +```text + + + / \ +2 3 +``` + +And `2 + (3 * 4)` would look like this: + +```text + + + / \ +2 * + / \ + 3 4 +``` + +### Arity + +Arity refers to the number of arguments a function or operation takes. + +```rust +let x = (2, 3); +let y = (4, 6); +let z = (8, 2, 6); +``` + +In the example above `x` and `y` have arity 2. `z` has arity 3. + +### Bound + +Bounds are constraints on a type or trait. For example, if a bound +is placed on the argument a function takes, types passed to that function +must abide by that constraint. + +### Combinator + +Combinators are higher-order functions that apply only functions and +earlier defined combinators to provide a result from its arguments. +They can be used to manage control flow in a modular fashion. + +### Dynamically Sized Type + +A dynamically sized type (DST) is a type without a statically known size or alignment. + +### Expression + +An expression is a combination of values, constants, variables, operators +and functions that evaluate to a single value, with or without side-effects. + +For example, `2 + (3 * 4)` is an expression that returns the value 14. + +### Statement + +A statement is the smallest standalone element of a programming language +that commands a computer to perform an action. \ No newline at end of file From 7c4241da0f0fc0bffc1d6059b193153e50eec58f Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Sat, 3 Jun 2017 14:09:13 +0800 Subject: [PATCH 2/9] Add definition of `slice`. --- src/glossory.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/glossory.md b/src/glossory.md index 45e37b588ab28..b606fafbb1df9 100644 --- a/src/glossory.md +++ b/src/glossory.md @@ -58,6 +58,14 @@ and functions that evaluate to a single value, with or without side-effects. For example, `2 + (3 * 4)` is an expression that returns the value 14. +### Slice + +A slice is dynamically-sized view into a contiguous sequence, written as `[T]`. + +It is often seen in its borrowed forms, either mutable or shared. The shared +slice type is `&[T]`, while the mutable slice type is `&mut [T]`, where `T` represents +the element type. + ### Statement A statement is the smallest standalone element of a programming language From bfc03d7156b50f073fb37e999b7c5402627a12d9 Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Sat, 3 Jun 2017 14:17:26 +0800 Subject: [PATCH 3/9] Add string literal and string slice. --- src/glossory.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/glossory.md b/src/glossory.md index b606fafbb1df9..1763a26ab16e9 100644 --- a/src/glossory.md +++ b/src/glossory.md @@ -69,4 +69,19 @@ the element type. ### Statement A statement is the smallest standalone element of a programming language -that commands a computer to perform an action. \ No newline at end of file +that commands a computer to perform an action. + +### String literal + +A string literal is a string stored directly in the final binary, and so will be +valid for the `'static` duration. + +Its type is `'static` duration borrowed string slice, `&'static str`. + +### String slice + +A string slice is the most primitive string type in Rust, written as `str`. It is +often seen in its borrowed forms, either mutable or shared. The shared +string slice type is `&str`, while the mutable string slice type is `&mut str`. + +Strings slices are always valid UTF-8. \ No newline at end of file From 79b034715378629466165de3c201bfdf468ec6ae Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Sat, 3 Jun 2017 14:19:47 +0800 Subject: [PATCH 4/9] Add about the prelude. --- src/glossory.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/glossory.md b/src/glossory.md index 1763a26ab16e9..c982df3e4778c 100644 --- a/src/glossory.md +++ b/src/glossory.md @@ -58,6 +58,11 @@ and functions that evaluate to a single value, with or without side-effects. For example, `2 + (3 * 4)` is an expression that returns the value 14. +### Prelude + +Prelude, or The Rust Prelude, is a small collection of items - mostly traits - that are +imported into very module of every crate. The traits in the prelude are pervasive. + ### Slice A slice is dynamically-sized view into a contiguous sequence, written as `[T]`. From c93ddb4138a235042b017b33a9e4342850809e6c Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Sat, 3 Jun 2017 14:29:05 +0800 Subject: [PATCH 5/9] Add definition of array. --- src/glossory.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/glossory.md b/src/glossory.md index c982df3e4778c..2e999f6f0bc8f 100644 --- a/src/glossory.md +++ b/src/glossory.md @@ -35,6 +35,12 @@ let z = (8, 2, 6); In the example above `x` and `y` have arity 2. `z` has arity 3. +### Array + +An array, sometimes also called a fixed-size array or an inline array, is a value +describing a collection of elements, each selected by an index that can be computed +at run time by the program. It occupies a contiguous region of memory. + ### Bound Bounds are constraints on a type or trait. For example, if a bound From 3817b2da65c350b43c96c2aea27494fe92431f2f Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Sat, 3 Jun 2017 14:29:54 +0800 Subject: [PATCH 6/9] Fix AST description. --- src/glossory.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/glossory.md b/src/glossory.md index 2e999f6f0bc8f..155624a7cc380 100644 --- a/src/glossory.md +++ b/src/glossory.md @@ -2,7 +2,7 @@ ### Abstract Syntax Tree -‘Abstract syntax tree’, or ‘AST’. This tree is an intermediate representation of +An ‘abstract syntax tree’, or ‘AST’, is an intermediate representation of the structure of your program when the compiler is compiling your program. For example, `2 + 3` can be turned into a tree: From 21928bd9c25aca97ef110d181191510187f0b1ad Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Sat, 3 Jun 2017 14:42:41 +0800 Subject: [PATCH 7/9] Adding definition of dispatch. This is from the first edition of the book. --- src/glossory.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/glossory.md b/src/glossory.md index 155624a7cc380..6276089133543 100644 --- a/src/glossory.md +++ b/src/glossory.md @@ -53,6 +53,13 @@ Combinators are higher-order functions that apply only functions and earlier defined combinators to provide a result from its arguments. They can be used to manage control flow in a modular fashion. +### Dispatch + +Dispatch is the mechanism to determine which specific version of code is actually +run when it involves polymorphism. Two major forms of dispatch are static dispatch and +dynamic dispatch. While Rust favors static dispatch, it also supports dynamic dispatch +through a mechanism called ‘trait objects’. + ### Dynamically Sized Type A dynamically sized type (DST) is a type without a statically known size or alignment. From 29050890b27876db626a3a57e131e1fb716e126c Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Sat, 3 Jun 2017 14:48:15 +0800 Subject: [PATCH 8/9] Add a definition of `trait`. This is from the first edition of the book. --- src/glossory.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/glossory.md b/src/glossory.md index 6276089133543..00886476e0a3c 100644 --- a/src/glossory.md +++ b/src/glossory.md @@ -102,4 +102,11 @@ A string slice is the most primitive string type in Rust, written as `str`. It i often seen in its borrowed forms, either mutable or shared. The shared string slice type is `&str`, while the mutable string slice type is `&mut str`. -Strings slices are always valid UTF-8. \ No newline at end of file +Strings slices are always valid UTF-8. + +### Trait + +A trait is a language item that is used for describing the functionalities a type must provide. +It allow a type to make certain promises about its behavior. + +Generic functions and generic structs can exploit traits to constrain, or bound, the types they accept. From 1d949d9f11d752e70bde98da50ccac554fb10f5c Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Sat, 3 Jun 2017 14:52:06 +0800 Subject: [PATCH 9/9] Minimize examples. --- src/glossory.md | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/src/glossory.md b/src/glossory.md index 00886476e0a3c..20a3a4456c524 100644 --- a/src/glossory.md +++ b/src/glossory.md @@ -3,37 +3,12 @@ ### Abstract Syntax Tree An ‘abstract syntax tree’, or ‘AST’, is an intermediate representation of -the structure of your program when the compiler is compiling your program. - -For example, `2 + 3` can be turned into a tree: - -```text - + - / \ -2 3 -``` - -And `2 + (3 * 4)` would look like this: - -```text - + - / \ -2 * - / \ - 3 4 -``` +the structure of the program when the compiler is compiling it. ### Arity Arity refers to the number of arguments a function or operation takes. - -```rust -let x = (2, 3); -let y = (4, 6); -let z = (8, 2, 6); -``` - -In the example above `x` and `y` have arity 2. `z` has arity 3. +For example, `(2, 3)` and `(4, 6)` have arity 2, and`(8, 2, 6)` has arity 3. ### Array