I’m learning Gleam, and I’m messing around with the syntax to get more familiar with it.
Today I learned that the last statement of a function or block can be a let. (Coming from F#, I did not expect that.)
Out of curiosity, I tried having a use as the last statement. That’s not ok, it emits a warning and crashes at runtime.
Is there a reason for this? Not that it matters, I’m just curious 😄 For some reason, edge cases is a fun way of learning for me.
import gleam/io
fn f1() {
// Ok, returns "joe"
let _ = "joe"
}
fn f2() {
// Not ok, emits warning and crashes at runtime
use _ <- g
}
fn g(cb) {
cb("joe")
}
pub fn main() {
io.println("Hello, " <> f2())
}
Btw, the warning is “A use expression must always be followed by at least one more
expression.” But use is not an expression, it’s a statement, isn’t it? Because it is not allowed where any expression is, it’s only allowed in functions and blocks, right? Just like let.