Skip to content

Commit c9454b1

Browse files
committed
Update "let is used to introduce variables" paragraph
1 parent d9146bf commit c9454b1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/doc/complement-design-faq.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,17 @@ This is to make the language easier to parse for humans, especially in the face
163163
of higher-order functions. `fn foo<T>(f: fn(int): int, fn(T): U): U` is not
164164
particularly easy to read.
165165

166-
## `let` is used to introduce variables
166+
## Why is `let` used to introduce variables?
167167

168-
`let` not only defines variables, but can do pattern matching. One can also
169-
redeclare immutable variables with `let`. This is useful to avoid unnecessary
170-
`mut` annotations. An interesting historical note is that Rust comes,
171-
syntactically, most closely from ML, which also uses `let` to introduce
172-
bindings.
168+
We don't use the term "variable", instead, we use "variable bindings". The
169+
simplest way for binding is the `let` syntax, other ways including `if let`,
170+
`while let` and `match`. Bindings also exist in function arguments positions.
171+
172+
Bindings always happen in pattern matching positions, and it's also Rust's way
173+
to declare mutability. One can also redeclare mutability of a binding in
174+
pattern matching. This is useful to avoid unnecessary `mut` annotations. An
175+
interesting historical note is that Rust comes, syntactically, most closely
176+
from ML, which also uses `let` to introduce bindings.
173177

174178
See also [a long thread][alt] on renaming `let mut` to `var`.
175179

0 commit comments

Comments
 (0)