News for hackers. Stuff that matters.
Re:Statements vs. Expressions by oxff on Thursday July 14, 2022 @07:02AM (#32094348)
Expressions `yield` values, statements don't yield values.

`square = square(4)` is a statement (a definition to be exact) that associates name `square` with the value `square(4)`.

The name `square` itself, when later used, is an expression, because when you call it, it evaluates to a value `square(4)`.

Re:Statements vs. Expressions by amadeuspagel on Thursday July 14, 2022 @07:14AM (#32094429)
For example, you might have tried writing something like this:

  foo = if (x < y) {
    ...
    ...
  }
Doesn't work because statements don't yield values.
Re:Statements vs. Expressions by Akronymus on Thursday July 14, 2022 @08:54AM (#32095446)
Thats one of the reason why I REALLY like languages where everything is an expression.

    let foo = 
        if x < y 
            somevalue
        else
            someothervalue
in f# for example.
Re:Statements vs. Expressions by bern4444 on Thursday July 14, 2022 @10:42PM (#32104054)
I also love F#. One of the most interesting languages that I've ever seen.

This is certainly another great aspect of it.

Re:Statements vs. Expressions by bern4444 on Thursday July 14, 2022 @10:43PM (#32104058)
So are ternaries expressions then too?

  const x = x < y ? 2 : 3;
Re:Statements vs. Expressions by amadeuspagel on Friday July 15, 2022 @06:03AM (#32106504)
Yes, indeed.