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 }.
This commit is contained in:
parent
b8cf2f8056
commit
93b2ddfc88
|
@ -1439,10 +1439,15 @@ call_closure_with_ten(closure);
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
Closures begin with the argument list between vertical bars and are followed by
|
Closures begin with the argument list between vertical bars and are followed by
|
||||||
a single expression. The types of the arguments are generally omitted,
|
a single expression. Remember that a block, `{ <expr1>; <expr2>; ... }`, is
|
||||||
as is the return type, because the compiler can almost always infer
|
considered a single expression: it evaluates to the result of the last
|
||||||
them. In the rare case where the compiler needs assistance, though, the
|
expression it contains if that expression is not followed by a semicolon,
|
||||||
arguments and return types may be annotated.
|
otherwise the block evaluates to `()`.
|
||||||
|
|
||||||
|
The types of the arguments are generally omitted, as is the return type,
|
||||||
|
because the compiler can almost always infer them. In the rare case where the
|
||||||
|
compiler needs assistance, though, the arguments and return types may be
|
||||||
|
annotated.
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
let square = |x: int| -> uint { x * x as uint };
|
let square = |x: int| -> uint { x * x as uint };
|
||||||
|
|
Loading…
Reference in New Issue