diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2015-04-08 11:34:12 -0400 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2015-04-08 11:34:12 -0400 |
| commit | 4cef7f296f1c986d7db36610a39f42c89028240f (patch) | |
| tree | 302d589ba156962c7aa8b833c83b302ac8736b34 | |
| parent | ac3cc6c427a77c59dd02912cf7178d3190a16720 (diff) | |
| parent | c9454b1a02754b8cdb46fec00241d5fd2171ef9e (diff) | |
| download | rust-4cef7f296f1c986d7db36610a39f42c89028240f.tar.gz rust-4cef7f296f1c986d7db36610a39f42c89028240f.zip | |
Rollup merge of #24149 - bombless:update-faq, r=steveklabnik
I think "let is used to introduce variables" is incorrent.
You can use
```rust
match (42, true) {
(x, y) => { /* ... */ }
}
```
to replace
```rust
let x = 42;
let y = true;
```
so it's nothing special for `let`.
| -rw-r--r-- | src/doc/complement-design-faq.md | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/doc/complement-design-faq.md b/src/doc/complement-design-faq.md index 3edbcbe62c5..0f2c37a5abf 100644 --- a/src/doc/complement-design-faq.md +++ b/src/doc/complement-design-faq.md @@ -163,13 +163,17 @@ This is to make the language easier to parse for humans, especially in the face of higher-order functions. `fn foo<T>(f: fn(int): int, fn(T): U): U` is not particularly easy to read. -## `let` is used to introduce variables +## Why is `let` used to introduce variables? -`let` not only defines variables, but can do pattern matching. One can also -redeclare immutable variables with `let`. This is useful to avoid unnecessary -`mut` annotations. An interesting historical note is that Rust comes, -syntactically, most closely from ML, which also uses `let` to introduce -bindings. +We don't use the term "variable", instead, we use "variable bindings". The +simplest way for binding is the `let` syntax, other ways including `if let`, +`while let` and `match`. Bindings also exist in function arguments positions. + +Bindings always happen in pattern matching positions, and it's also Rust's way +to declare mutability. One can also redeclare mutability of a binding in +pattern matching. This is useful to avoid unnecessary `mut` annotations. An +interesting historical note is that Rust comes, syntactically, most closely +from ML, which also uses `let` to introduce bindings. See also [a long thread][alt] on renaming `let mut` to `var`. |
