3 ms·
Fun seeing that pretty much everyone else finds that idiom confusing too. Half-serious, over breakfast: (case [(> n min) (< n max)] [true true] n
by throwawaw 6y ago
Fun seeing that pretty much everyone else finds that idiom confusing too. Half-serious, over breakfast:
(case [(> n min) (< n max)]
[true true] n
[true false] max
[false true] min)
(Side note: Clojure's `>` and `<` are kind of unreadable to begin with. Turning `if (> n min)` into "if n is greater than min" takes some work for me, still, after more than a year.)
- retzkek 6y agoHowever, prefix notation becomes much easier to read and reason about when you have more than two things to compare: (> 3 2 1 ...) vs (3 > 2) && (2 > 1) && ...
- kickopotomus 6y agoAlternatively, since min and max are part of clojure.core: (-> n (max vmin) (min vmax))
- white-flame 6y agoWhat about the [false false] case where min ≥ n ≥ max?
- LandR 6y ago> (Side note: Clojure's `>` and `<` are kind of unreadable to begin with. I felt the same for awhile but now I just mentally put the operator between the operands, so (> 3 2) is the same as 3 > 2.