Skip to content

Commit 6b564a6

Browse files
committed
Rollup merge of rust-lang#27232 - Dangthrimble:master, r=steveklabnik
Added definitions for 'Expression', 'Expression-Oriented Language' and 'Statement' to glossary. Sorted the definitions alphabetically. r? @steveklabnik
2 parents 56bb9ed + 8fee567 commit 6b564a6

File tree

2 files changed

+49
-20
lines changed

2 files changed

+49
-20
lines changed

src/doc/trpl/glossary.md

+42-16
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,12 @@
33
Not every Rustacean has a background in systems programming, nor in computer
44
science, so we've added explanations of terms that might be unfamiliar.
55

6-
### Arity
7-
8-
Arity refers to the number of arguments a function or operation takes.
9-
10-
```rust
11-
let x = (2, 3);
12-
let y = (4, 6);
13-
let z = (8, 2, 6);
14-
```
15-
16-
In the example above `x` and `y` have arity 2. `z` has arity 3.
17-
186
### Abstract Syntax Tree
197

20-
When a compiler is compiling your program, it does a number of different
21-
things. One of the things that it does is turn the text of your program into an
22-
‘abstract syntax tree’, or ‘AST’. This tree is a representation of the
23-
structure of your program. For example, `2 + 3` can be turned into a tree:
8+
When a compiler is compiling your program, it does a number of different things.
9+
One of the things that it does is turn the text of your program into an
10+
‘abstract syntax tree’, or ‘AST’. This tree is a representation of the structure
11+
of your program. For example, `2 + 3` can be turned into a tree:
2412

2513
```text
2614
+
@@ -37,3 +25,41 @@ And `2 + (3 * 4)` would look like this:
3725
/ \
3826
3 4
3927
```
28+
29+
### Arity
30+
31+
Arity refers to the number of arguments a function or operation takes.
32+
33+
```rust
34+
let x = (2, 3);
35+
let y = (4, 6);
36+
let z = (8, 2, 6);
37+
```
38+
39+
In the example above `x` and `y` have arity 2. `z` has arity 3.
40+
41+
### Expression
42+
43+
In computer programming, an expression is a combination of values, constants,
44+
variables, operators and functions that evaluate to a single value. For example,
45+
`2 + (3 * 4)` is an expression that returns the value 14. It is worth noting
46+
that expressions can have side-effects. For example, a function included in an
47+
expression might perform actions other than simply returning a value.
48+
49+
### Expression-Oriented Language
50+
51+
In early programming languages, [expressions][expression] and
52+
[statements][statement] were two separate syntactic categories: expressions had
53+
a value and statements did things. However, later languages blurred this
54+
distinction, allowing expressions to do things and statements to have a value.
55+
In an expression-oriented language, (nearly) every statement is an expression
56+
and therefore returns a value. Consequently, these expression statements can
57+
themselves form part of larger expressions.
58+
59+
[expression]: glossary.html#expression
60+
[statement]: glossary.html#statement
61+
62+
### Statement
63+
64+
In computer programming, a statement is the smallest standalone element of a
65+
programming language that commands a computer to perform an action.

src/doc/trpl/hello-world.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,13 @@ string to the screen. Easy enough!
111111

112112
[allocation]: the-stack-and-the-heap.html
113113

114-
Finally, the line ends with a semicolon (`;`). Rust is an ‘expression oriented’
115-
language, which means that most things are expressions, rather than statements.
116-
The `;` is used to indicate that this expression is over, and the next one is
117-
ready to begin. Most lines of Rust code end with a `;`.
114+
Finally, the line ends with a semicolon (`;`). Rust is an [‘expression oriented’
115+
language][expression-oriented language], which means that most things are
116+
expressions, rather than statements. The `;` is used to indicate that this
117+
expression is over, and the next one is ready to begin. Most lines of Rust code
118+
end with a `;`.
119+
120+
[expression-oriented language]: glossary.html#expression-oriented-language
118121

119122
Finally, actually compiling and running our program. We can compile with our
120123
compiler, `rustc`, by passing it the name of our source file:

0 commit comments

Comments
 (0)