3
3
> ** <sup >Syntax</sup >** \
4
4
> _ ClosureExpression_ :\
5
5
>   ;  ; ` move ` <sup >?</sup >\
6
- >   ;  ; ( ` || ` | ` | ` [ _ FunctionParameters _ ] <sup >?</sup > ` | ` )\
6
+ >   ;  ; ( ` || ` | ` | ` _ ClosureParameters _ <sup >?</sup > ` | ` )\
7
7
>   ;  ; ([ _ Expression_ ] | ` -> ` [ _ TypeNoBounds_ ]   ; [ _ BlockExpression_ ] )
8
+ >
9
+ > _ ClosureParameters_ :\
10
+ >   ;  ; _ ClosureParam_ (` , ` _ ClosureParam_ )<sup >\* </sup > ` , ` <sup >?</sup >
11
+ >
12
+ > _ ClosureParam_ :\
13
+ >   ;  ; [ _ Pattern_ ]   ; ( ` : ` [ _ Type_ ] )<sup >?</sup >
8
14
9
15
A _ closure expression_ defines a closure and denotes it as a value, in a single
10
16
expression. A closure expression is a pipe-symbol-delimited (` | ` ) list of
@@ -14,11 +20,11 @@ type, the expression used for the body of the closure must be a normal
14
20
[ block] . A closure expression also may begin with the
15
21
` move ` keyword before the initial ` | ` .
16
22
17
- A closure expression denotes a function that maps a list of parameters
18
- ( ` ident_list ` ) onto the expression that follows the ` ident_list ` . The patterns
19
- in the ` ident_list ` are the parameters to the closure. If a parameter's types
20
- is not specified, then the compiler infers it from context . Each closure
21
- expression has a unique anonymous type.
23
+ A closure expression denotes a function that maps a list of parameters onto
24
+ the expression that follows the parameters. Just like a [ ` let ` binding ] , the
25
+ parameters are irrefutable [ patterns ] , whose type annotation is optional and
26
+ will be inferred from context if not given . Each closure expression has a
27
+ unique, anonymous type.
22
28
23
29
Closure expressions are most useful when passing functions as arguments to other
24
30
functions, as an abbreviation for defining and capturing a separate function.
@@ -69,3 +75,6 @@ ten_times(move |j| println!("{}, {}", word, j));
69
75
[ _BlockExpression_ ] : expressions/block-expr.html
70
76
[ _TypeNoBounds_ ] : types.html#type-expressions
71
77
[ _FunctionParameters_ ] : items/functions.html
78
+ [ _Pattern_ ] : patterns.html
79
+ [ _Type_ ] : types.html#type-expressions
80
+ [ `let` binding ] : statements.html#let-statements
0 commit comments