I don't really get it.. In one of the last example's he writes:
` if (node.last_child(s) is Ok(last_child))`
Is the part between the () not ultimately the same as a boolean expression? Like he wrote his own implementation of if/else syntax?
Also in the beginning he says: "An if with an else can produce a value", but isn't this just 'syntactic sugar'? I think the code that actually runs is the same as if you'd write if (value x = some_value) {value = something} else {value = something_else} ?
About the `if else` producing a value matter. Well, if you look at things that way, C can be said to be syntactic sugar of assembly, as for every C program you can write equivalent assembly. `if else` producing value is very useful because it allows you to write if else wherever a value is expected. You can call methods on an `if else` or pass one as an argument of function. When such an expression is sufficiently complex your equivalent code using non-value-producing `if else` would be a lot more verbose and unreadable.
This is equivalent to the `if let` syntax of Rust. In Rust at least this is treated as a special syntax but not a boolean. I once complained it's kinda confusing that it makes one think the `let` pattern matching syntax is a boolean expression which it is not, and the Rust people replied to me saying yeah it can be a boolean maybe at some point in the future. So yeah whether such syntax makes pattern matching a boolean really is just a matter of whether it's said to be one.
Yeah okay I get it. The law basically states that 'not true' should be 'false' and vice versa.
I still don't get what's the use of this, or is this just a curiosity? It seems like the result is just a kind of ternary operator? Doesn't this still just compile to if(x.present) return x else y? Just with really obtuse syntax
If you are doing proofs then the law of the excluded middle creates paradoxes. "this statement is false" is a paradox with the law but isn't without the law. In a programming language not used for proofs? Then yeah it is just for fun.
` if (node.last_child(s) is Ok(last_child))`
Is the part between the () not ultimately the same as a boolean expression? Like he wrote his own implementation of if/else syntax?
Also in the beginning he says: "An if with an else can produce a value", but isn't this just 'syntactic sugar'? I think the code that actually runs is the same as if you'd write if (value x = some_value) {value = something} else {value = something_else} ?