2 ms·
I see (if (< (* a b) c))) and think why didn't you use cond?! :)
by taylodl 7y ago
I see (if (< (* a b) c))) and think why didn't you use cond?! :)
- kazinator 7y ago(if a b c) translates to, for instance in Common Lisp, (cond (a b) (t c)): four more parentheses and an extra symbol. cond came first; if was invented later for less verbiage in the common case of testing a single condition, where the consequent and alternative are single expressions. cond is better than if when you find yourself stuffing progn bodies into the if. (if a (progn b c) (progn d e)) -> (cond (a b c) (t d e)).
- taylodl 7y agoI'm sorry, I was attempting humor! You're absolutely right though - use if for if-then-else type logic, use cond for testing multiple conditions. cond corresponds more to switch from the c family of languages.