4 ms·
Stray thought while reading the documentation, inspired by how easy it is to convert a variable to a function: is there any reason to include a separate switch
by smichel17 7y ago
Stray thought while reading the documentation, inspired by how easy it is to convert a variable to a function: is there any reason to include a separate switch statement at all? It seems like you could use `if` there with a similar syntax:
getSignZero(n) = if {
n > 0 then Positive
n < 0 then Negative
else Zero
}
- caditinpiscinam 7y agoSimilar story as with objects - the switch statement originally existed to facilitate type-aware conditionals for statically checked algebraic data-types. At this point it's just syntactic sugar for a chain of conditionals. It might make sense to unify the two constructs - and I like the syntax you suggest
- rurban 7y agoOr cond. Which is more like what you did. Not if, which is everywhere a binop. switch takes a block with seperate syntax, but cond just a list of expressions and statements.