Little things that matter in language design: make it do what it looks like it does
Little things that matter in language design: make it do what it looks like it does
Posted Dec 28, 2014 8:29 UTC (Sun) by maryjmcdermott57 (guest, #100380)In reply to: Little things that matter in language design: make it do what it looks like it does by neilbrown
Parent article: Little things that matter in language design
I want to ask one question about Rust.
First of all, I want to say thank you for your article. You have the answer for my question (the section "semicolons & expression"), that I asked when should add ; at the end of whole if/else expression because it's also an expression. I asked that question in many forums but many people either not pay attention to it or thinking that it's as a silly question.
But as you answered my question. This leads to more questions.
As you said, I assume that in Rust, if the expression return the unit-() type then we wouldn't require add ; at the end of that expression.
As before, if the internal of if/else expression (i.e function call return unit-() type then we won't necessary add ; at the end of either each internal function call or the whole if/else expression.
So what about the function call outside of if/else expression.
The rule seems not true anymore
I mean I have this code
fn main() {
println!("hello") // I think don't need add ; at here but it's wrong
println!("world") // I think don't need add ; at here but it's wrong
}
As the code run, compile raise error. Why does that happens when println!() return unit-() type? So as the assumption above, this code should work.
And can I ask you one more question? Is the function declaration is expression or not? Because I don't see the ; at the end of } of function declaration. I mean if it's an expression, it should look like this
fn foo() {
// do something
}; // ; should add in here but in practical, it's not there