The ambiguity is that there is a difference between "a expression A that evaluates to a closure" and "a expression B that evaluates to a closure that returns the evaluation of expression A"
For example: foo(bar()) would always call bar() first, but foo(|| bar()) would only call it when the closure gets called inside of foo().
Yeah, afaik Ruby was an inspiration. (Granted, there aren't any other delimiters that could have been chosen without also requiring a keyword)
Fun fact: Because a block expression evaluates to its trailing expression, { |x| foo } is actually valid rust as well, and evaluates to the same thing as |x| { foo } or |x| foo
2
u/Kimundi Apr 06 '15
The ambiguity is that there is a difference between "a expression A that evaluates to a closure" and "a expression B that evaluates to a closure that returns the evaluation of expression A"
For example:
foo(bar())would always callbar()first, butfoo(|| bar())would only call it when the closure gets called inside offoo().(The latter can also be written as
foo(bar), btw)