2014-11-25 18:30 GMT+01:00 David Pidcock :
> While I think the latter two solutions show off Clojures ease of
> extensibility, I personally believe the first technique is more appropriate
> for the current wxample.
>
> I mean, how many different ways of calculating and rounding a percentage
> are
2014-11-25 14:31 GMT+01:00 Gary Verhaegen :
> Add an arity 3 version which takes a symbol and dispatches on it. You can
> choose the position that you like best; to keep in line with your current
> scheme:
>
> (defn get-percentage
> ([place total-count] (get-percentage :normal place total-count)
While I think the latter two solutions show off Clojures ease of extensibility,
I personally believe the first technique is more appropriate for the current
wxample.
I mean, how many different ways of calculating and rounding a percentage are
there?
--
You received this message because you
Also, you can use multi-methods:
(defmulti get-percentage (fn [x mode] mode))
(defmethod get-percentage :default
[x _]
(get-percentage x :high))
(defmethod get-percentage :high
[x _]
...)
(defmethod get-percentage :low
[x _]
...)
This has the advantage to not only having a clear de
On Tuesday, November 25, 2014 8:32:14 AM UTC-5, Gary Verhaegen wrote:
>
> Add an arity 3 version which takes a symbol and dispatches on it. You can
> choose the position that you like best; to keep in line with your current
> scheme:
>
> (defn get-percentage
> ([place total-count] (get-percenta
Add an arity 3 version which takes a symbol and dispatches on it. You can
choose the position that you like best; to keep in line with your current
scheme:
(defn get-percentage
([place total-count] (get-percentage :normal place total-count))
([mode place total-count]
(condp = mode
:l
I started playing with Clojure again. I made the following three functions:
(defn get-percentage [place total-count]
(int (Math/round (double (/ (* place 100) total-count)
(defn get-percentage-low [place total-count]
(int (Math/floor (/ (* place 100) total-count
(d