Re:Math.min(Math.max(num, min), max)
by throwawaw on Thursday August 20, 2020 @11:18AM
(#24224148)
Fun seeing that pretty much everyone else finds that idiom confusing too. Half-serious, over breakfast:
(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.)
[ Parent
| on HN ]
However, 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) && ...
Re:Math.min(Math.max(num, min), max)
by kickopotomus on Thursday August 20, 2020 @12:21PM
(#24224857)
Alternatively, since min and max are part of clojure.core:
(-> n
(max vmin)
(min vmax))> (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.
Re:Math.min(Math.max(num, min), max)
by white-flame on Thursday August 20, 2020 @01:28PM
(#24225896)
What about the [false false] case where min ≥ n ≥ max?