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.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.I also love F#. One of the most interesting languages that I've ever seen.
This is certainly another great aspect of it.
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.
`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)`.