Re:Rust for Web
by tatterdemalion on Monday February 01, 2016 @12:48AM
(#11010025)
This is not accurate. Rust is an expression based language, and `if let`s are expressions. If an `if` or `if let` returns (), it does not need an else.
[ Parent
| on HN ]
> Rust is an expression based language
I initially considered writing that, but it depends on what the original poster means by "expression-based language" and they haven't made that clear: in Rust, a function is a sequence of statements. An assignment is a statement for instance, not an expression. To me an expression-based language is something like Haskell or Elm, not only do you have ubiquitous expressions (which Rust does have) there's really no such thing as a statement, a program (or function) simply is an expression (possibly with multiple components) this Rust:
let a = 1;
let b = 2;
a + b
is 3 statements. The equivalent Elm or Haskell is a single expression: let
a = 1
b = 2
in
a + b
Re:Rust for Web
by tatterdemalion on Monday February 01, 2016 @12:01PM
(#11013055)
Everything at the function level that isn't `let` is an expression. And that `let` is not an expression is just an aspect of Rust that reduces boilerplate and rightward drift; the block containing those three statements in your example is still an expression which evaluates to the same thing as the Haskell below.
The original commenter seems to mean 'purely functional' rather than 'expression based'. OCaml uses `let in`, but still has side effects.
Re:Rust for Web
by CuriousSkeptic on Monday February 01, 2016 @07:31PM
(#11016846)
Perhaps a better world would be referentially transparent. Thought I'd avoid a debate about what constitute functional. But here we are...
Re:Rust for Web
by tatterdemalion on Friday February 05, 2016 @02:05PM
(#11043775)
The issue you're talking about is purity (not having side effects). Many expression based languages have side effects, such as Rust, OCaml, or Common Lisp.