I think you could replace your condp = with case, since all your mode
keywords are known at compile-time, otherwise looks about right.

On Tue Feb 10 2015 at 11:32:58 PM Cecil Westerhof <cldwester...@gmail.com>
wrote:

> I needed a function to get the percentage as an int. Input is place and
> total-count.
> I want the normal definition (which is the default) and a high and low
> variant.
>
> I came up with the following code:
>     (defn get-percentage
>       ([place total-count] (get-percentage :normal place total-count))
>       ([mode place total-count]
>         (let [percentage (/ (* place 100.0) total-count)]
>           (condp = mode
>             :high     (int (Math/ceil  percentage))
>             :low      (int (Math/floor percentage))
>             :normal   (int (Math/round percentage))
>             (throw (Exception. "ERROR: get-percentage [:high|:low|:normal]
> <PLACE> <TOTAL_COUNT>"))))))
>
> Is this a good version, or could it be done better?
>
> --
> Cecil Westerhof
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to