From 1f80880467c6bab0903b7790c9b40a3d4c92a47c Mon Sep 17 00:00:00 2001 From: Jonathan Hansford Date: Thu, 23 Jul 2015 12:24:55 +0100 Subject: [PATCH 1/4] Added entries to explain expression-oriented languages Added definitions for 'Expression', 'Expression-Oriented Language' and 'Statement'. Sorted the definitions alphabetically. --- src/doc/trpl/glossary.md | 56 ++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/src/doc/trpl/glossary.md b/src/doc/trpl/glossary.md index c97da0e95b823..bd425145b96c8 100644 --- a/src/doc/trpl/glossary.md +++ b/src/doc/trpl/glossary.md @@ -3,24 +3,12 @@ Not every Rustacean has a background in systems programming, nor in computer science, so we've added explanations of terms that might be unfamiliar. -### 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. - ### Abstract Syntax Tree -When a compiler is compiling your program, it does a number of different -things. One of the things that it does is turn the text of your program into an -‘abstract syntax tree’, or ‘AST’. This tree is a representation of the -structure of your program. For example, `2 + 3` can be turned into a tree: +When a compiler is compiling your program, it does a number of different things. +One of the things that it does is turn the text of your program into an +‘abstract syntax tree’, or ‘AST’. This tree is a representation of the structure +of your program. For example, `2 + 3` can be turned into a tree: ```text + @@ -37,3 +25,39 @@ And `2 + (3 * 4)` would look like this: / \ 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. + +### Expression + +In computer programming, an expression is a combination of values, constants, +variables, operators and functions that evaluate to a single value. For example, +`2 + (3 * 4)` is an expression that returns the value 14. It is worth noting +that expressions can have side-effects. For example, a function included in an +expression might perform actions other than simply returning a value. + +### Expression-Oriented Language + +In early programming languages [expressions] and [statements] were two separate +syntactic categories: expressions had a value and statements did things. +However, later languages blurred this distinction, allowing expressions to do +things and statements to have a value. In an expression-oriented language, +(nearly) every statement is an expression and therefore returns a value. + +[expressions]: glossary.html#expression +[statements]: glossary.html#statement + +### Statement + +In computer programming, a statement is the smallest standalone element of a +programming language that commands a computer to perform an action. From 30584b06efd06899f3cb99cffeef5ac61913bf22 Mon Sep 17 00:00:00 2001 From: Jonathan Hansford Date: Fri, 24 Jul 2015 09:01:34 +0100 Subject: [PATCH 2/4] Additional information on Expression-Oriented Languages Added the fact that expression statements can form part of larger expressions. --- src/doc/trpl/glossary.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/doc/trpl/glossary.md b/src/doc/trpl/glossary.md index bd425145b96c8..900211200aff5 100644 --- a/src/doc/trpl/glossary.md +++ b/src/doc/trpl/glossary.md @@ -53,6 +53,8 @@ syntactic categories: expressions had a value and statements did things. However, later languages blurred this distinction, allowing expressions to do things and statements to have a value. In an expression-oriented language, (nearly) every statement is an expression and therefore returns a value. +Consequently these expression statements can themselves form part of larger +expressions. [expressions]: glossary.html#expression [statements]: glossary.html#statement From bcee0a83b8ffd02269bd7cfa23bc1fc760719393 Mon Sep 17 00:00:00 2001 From: Jonathan Hansford Date: Fri, 24 Jul 2015 12:12:11 +0100 Subject: [PATCH 3/4] Added link in glossary to expression-oriented language Tidied up glossary.md and added link from hello-world.md to 'expression-oriented language' in glossary.md --- src/doc/trpl/glossary.md | 20 ++++++++++---------- src/doc/trpl/hello-world.md | 11 +++++++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/doc/trpl/glossary.md b/src/doc/trpl/glossary.md index 900211200aff5..46d87e51f0d08 100644 --- a/src/doc/trpl/glossary.md +++ b/src/doc/trpl/glossary.md @@ -48,16 +48,16 @@ expression might perform actions other than simply returning a value. ### Expression-Oriented Language -In early programming languages [expressions] and [statements] were two separate -syntactic categories: expressions had a value and statements did things. -However, later languages blurred this distinction, allowing expressions to do -things and statements to have a value. In an expression-oriented language, -(nearly) every statement is an expression and therefore returns a value. -Consequently these expression statements can themselves form part of larger -expressions. - -[expressions]: glossary.html#expression -[statements]: glossary.html#statement +In early programming languages [expressions][expression] and +[statements][statement] were two separate syntactic categories: expressions had +a value and statements did things. However, later languages blurred this +distinction, allowing expressions to do things and statements to have a value. +In an expression-oriented language, (nearly) every statement is an expression +and therefore returns a value. Consequently these expression statements can +themselves form part of larger expressions. + +[expression]: glossary.html#expression +[statement]: glossary.html#statement ### Statement diff --git a/src/doc/trpl/hello-world.md b/src/doc/trpl/hello-world.md index eec6fe62f22b3..cd4326a28d809 100644 --- a/src/doc/trpl/hello-world.md +++ b/src/doc/trpl/hello-world.md @@ -111,10 +111,13 @@ string to the screen. Easy enough! [allocation]: the-stack-and-the-heap.html -Finally, the line ends with a semicolon (`;`). Rust is an ‘expression oriented’ -language, which means that most things are expressions, rather than statements. -The `;` is used to indicate that this expression is over, and the next one is -ready to begin. Most lines of Rust code end with a `;`. +Finally, the line ends with a semicolon (`;`). Rust is an [‘expression oriented’ +language][expression-oriented language], which means that most things are +expressions, rather than statements. The `;` is used to indicate that this +expression is over, and the next one is ready to begin. Most lines of Rust code +end with a `;`. + +[expression-oriented language]: glossary.html#expression-oriented-language Finally, actually compiling and running our program. We can compile with our compiler, `rustc`, by passing it the name of our source file: From 8fee56777c2b88509e81e5e71773e1b588fee614 Mon Sep 17 00:00:00 2001 From: Jonathan Hansford Date: Sat, 25 Jul 2015 10:42:46 +0100 Subject: [PATCH 4/4] Commas added, as requested. --- src/doc/trpl/glossary.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/glossary.md b/src/doc/trpl/glossary.md index 46d87e51f0d08..307aef8018066 100644 --- a/src/doc/trpl/glossary.md +++ b/src/doc/trpl/glossary.md @@ -48,12 +48,12 @@ expression might perform actions other than simply returning a value. ### Expression-Oriented Language -In early programming languages [expressions][expression] and +In early programming languages, [expressions][expression] and [statements][statement] were two separate syntactic categories: expressions had a value and statements did things. However, later languages blurred this distinction, allowing expressions to do things and statements to have a value. In an expression-oriented language, (nearly) every statement is an expression -and therefore returns a value. Consequently these expression statements can +and therefore returns a value. Consequently, these expression statements can themselves form part of larger expressions. [expression]: glossary.html#expression