Hacker News new | past | comments | ask | show | jobs | submit login

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.



cond 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)


cond 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.


You 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.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: