Skip to content

Commit 93b2ddf

Browse files
committed
A reminder that a block is a single expr in closures
This is something that's only been briefly mentioned in the beginning of the tutorial and all of the closure examples within this subsection include only one expression between { and }.
1 parent b8cf2f8 commit 93b2ddf

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

doc/tutorial.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,10 +1439,15 @@ call_closure_with_ten(closure);
14391439
~~~~
14401440

14411441
Closures begin with the argument list between vertical bars and are followed by
1442-
a single expression. The types of the arguments are generally omitted,
1443-
as is the return type, because the compiler can almost always infer
1444-
them. In the rare case where the compiler needs assistance, though, the
1445-
arguments and return types may be annotated.
1442+
a single expression. Remember that a block, `{ <expr1>; <expr2>; ... }`, is
1443+
considered a single expression: it evaluates to the result of the last
1444+
expression it contains if that expression is not followed by a semicolon,
1445+
otherwise the block evaluates to `()`.
1446+
1447+
The types of the arguments are generally omitted, as is the return type,
1448+
because the compiler can almost always infer them. In the rare case where the
1449+
compiler needs assistance, though, the arguments and return types may be
1450+
annotated.
14461451

14471452
~~~~
14481453
let square = |x: int| -> uint { x * x as uint };

0 commit comments

Comments
 (0)