Hacker News new | ask | show | jobs
by scribu 4685 days ago
So the last statement in a block for a matched if condition gets assigned to the variable? That's pretty cool.
2 comments

Any language that emphasizes expressions over statements will have this feature. Off the top of my head, that should include Haskell, Scala, CoffeeScript, Ruby, Elixir, Clojure (hell, anything Lisp really)...

The idea is that while you may be able to traverse code-paths with side effects in some of these languages, they encourage treating a line of code (term used loosely, as an expression can span multiple lines) as a computable value. It may take a bit of getting used to at first, but from my own experience, it now feels weird and awkward when a language doesn't.

Reminds me of looking at a nasty language like MUMPS or something, where persistence is built into the core language; statement-oriented languages tend not to be composable.

By leaving off the semicolon, you can make a block (which is anything in braces) evaluate to the value of its final expression. It's one of those rules that seems perfectly terrible at first blush, but actually seems to work really well in practice thanks to Rust's strong static typing.