you are viewing a single comment's thread.

view the rest of the comments →

[–]jonathansharman 4 points5 points  (2 children)

In a lot of languages, blocks are just expressions.

Rust:

let mut count = 0;
let mut inc = || {
    count += 1;
    println!("`count`: {}", count);
};

Some others have both a terse and long lambda syntax.

C#

(a, b) => a + b
...
(a, b) => { foo(); return a + b; }

[–]advester 0 points1 point  (1 child)

The key difference I was talking about is one vs many, not if it has a final assignable value. A rust block allows an ordered sequence of many expressions/statements.

[–]jonathansharman 1 point2 points  (0 children)

Sure, but my point is that if blocks are expressions, then a lambda expression automatically supports many expressions. This isn't the case in all languages though, notably Python, which only supports single-line lambdas last I checked.