3 ms·
Not necessarily. In many Lisps you can bind the result of a condition like so. (let [thing (cond pred-1 form-1 ...
by koito17 2y ago
Not necessarily. In many Lisps you can bind the result of a condition like so.
(let [thing (cond
pred-1 form-1
...
pred-n form-n)]
(do something with thing))
This makes laying out React components in ClojureScript feel "natural" compared to JSX/TSX, where instead one nests ternaries or performs a handful of early returns. Both of these options negatively impact readability of code.
- runevault 2y agocond isn't a trinary operator it is more of a switch statement. Trinary is expressly let x = condition ? truevalue : falsevalue You can do shenanigans by having something along the lines of let x = condition1 ? truevalue1 : (condition2 ? truevalue2 : falsevalue)
- koito17 2y agocond is neither an operator nor a statement, it's an expression. This is a demonstration of a conditional expression handling multiple conditions, which GP wanted. More importantly, pattern matching is not necessary here.
- runevault 2y agoYou misunderstood. They were talking specifically about languages that only have ternary operators as a way to do if-as-expression, and why they prefer languages with either real if-else if-else expressions or full switch/pattern matching as expression.