Sorry to be pedantic, and yes I was aware of that special rule and frankly I think that is silly that only don’t need to put a semicolon on the last block that is the result expression. I’d prefer never put semicolons and the result expression would also be the value of the last expression in the block, or
() if the last statement in the block is not an expression, e.g. a
I knew that
return was optional on the last line, but I didn’t know if Rust was capable of recognizing
if-else as an expression (and I actually thought of checking it since Scala can, but…). I don’t make such assumptions (and hadn’t bothered to try it because I like general, consistent rules so I don’t need to try it in order to not be surprised), because of the special case rules instead of a general one that everything is a expression (and not statement which I think one of the reasons Scala didn’t include
while) or my generalized variant (to allow for
The 2 cents issue for me with lambdas is consistency. Since
-> is used to indicate result type on functions, it would be more consistent IMO if it is also used to indicate the result expression for lambdas (anonymous functions). Here I must also criticize Scala for using
: for function result types (consistent with function arguments yet…) and
=> for lambdas (which is non-standard from the
-> of Haskel et al, and appears to be an attempt at consistency with
= for function blocks that are expressions instead of brace-delimited blocks).
I am just arguing that lack of special cases, makes memorizing and learning a language less surprising.