Skip to content

Commit

Permalink
A reminder that a block is a single expr in closures
Browse files Browse the repository at this point in the history
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 }.
  • Loading branch information
alco committed Jun 8, 2013
1 parent b8cf2f8 commit 93b2ddf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions doc/tutorial.md
Expand Up @@ -1439,10 +1439,15 @@ call_closure_with_ten(closure);
~~~~

Closures begin with the argument list between vertical bars and are followed by
a single expression. 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.
a single expression. Remember that a block, `{ <expr1>; <expr2>; ... }`, is
considered a single expression: it evaluates to the result of the last
expression it contains if that expression is not followed by a semicolon,
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 };
Expand Down

5 comments on commit 93b2ddf

@bors
Copy link
Contributor

@bors bors commented on 93b2ddf Jun 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 93b2ddf Jun 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alco/rust/tutorial-block-expr = 93b2ddf into auto

@bors
Copy link
Contributor

@bors bors commented on 93b2ddf Jun 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alco/rust/tutorial-block-expr = 93b2ddf merged ok, testing candidate = 1cf57f7

@bors
Copy link
Contributor

@bors bors commented on 93b2ddf Jun 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 93b2ddf Jun 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 1cf57f7

Please sign in to comment.