News for hackers. Stuff that matters.
Re:Statements vs. Expressions by hibbelig on Thursday July 14, 2022 @05:59AM (#32094002)
I can't think of an example where

    let x = <something>;
compiles but

    <something>;
does not compile. I think all expressions are statements.
Re:Statements vs. Expressions by lmm on Thursday July 14, 2022 @06:40AM (#32094216)
Some languages forbid "obviously pure" expressions like "0" as statements (since using them as a statement is probably a mistake).
Re:Statements vs. Expressions by hibbelig on Friday July 15, 2022 @09:37AM (#32108047)
I think I was saying that Javascript is not one of them.
Re:Statements vs. Expressions by mxben on Thursday July 14, 2022 @07:36AM (#32094591)
Interesting! Any examples of such languages?
Re:Statements vs. Expressions by lmm on Thursday July 14, 2022 @05:14PM (#32101542)
Java is one popular example. You get "error: not a statement".
Re:Statements vs. Expressions by bluepnume on Thursday July 14, 2022 @08:03PM (#32102878)
Right. They're not mutually exclusive -- hence the "both, either, or neither"
Re:Statements vs. Expressions by hibbelig on Friday July 15, 2022 @09:37AM (#32108041)
My point was that there are four combinations, and "both, either, or neither" suggests that all four can happen. But actually, only three out of four can happen.

It can be both a statement and an expression. Yes.

It can be neither a statement nor an expression. Yes.

It can be a statement but not an expression. Yes.

But the case that it is an expression but not a statement: this case never happens.