]> git.proxmox.com Git - rustc.git/blame - src/doc/trpl/glossary.md
Imported Upstream version 1.3.0+dfsg1
[rustc.git] / src / doc / trpl / glossary.md
CommitLineData
85aaf69f
SL
1% Glossary
2
3Not every Rustacean has a background in systems programming, nor in computer
4science, so we've added explanations of terms that might be unfamiliar.
5
c34b1796
AL
6### Abstract Syntax Tree
7
c1a9b12d
SL
8When a compiler is compiling your program, it does a number of different things.
9One 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
11of your program. For example, `2 + 3` can be turned into a tree:
c34b1796
AL
12
13```text
14 +
15 / \
162 3
17```
18
19And `2 + (3 * 4)` would look like this:
20
21```text
22 +
23 / \
242 *
25 / \
26 3 4
27```
c1a9b12d
SL
28
29### Arity
30
31Arity refers to the number of arguments a function or operation takes.
32
33```rust
34let x = (2, 3);
35let y = (4, 6);
36let z = (8, 2, 6);
37```
38
39In the example above `x` and `y` have arity 2. `z` has arity 3.
40
41### Expression
42
43In computer programming, an expression is a combination of values, constants,
44variables, 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
46that expressions can have side-effects. For example, a function included in an
47expression might perform actions other than simply returning a value.
48
49### Expression-Oriented Language
50
51In early programming languages, [expressions][expression] and
52[statements][statement] were two separate syntactic categories: expressions had
53a value and statements did things. However, later languages blurred this
54distinction, allowing expressions to do things and statements to have a value.
55In an expression-oriented language, (nearly) every statement is an expression
56and therefore returns a value. Consequently, these expression statements can
57themselves form part of larger expressions.
58
59[expression]: glossary.html#expression
60[statement]: glossary.html#statement
61
62### Statement
63
64In computer programming, a statement is the smallest standalone element of a
65programming language that commands a computer to perform an action.