2015-02-15 10:23 GMT+01:00 Atamert Ölçgen <mu...@muhuk.com>:

>
>
> On Sat, Feb 14, 2015 at 6:08 PM, Cecil Westerhof <cldwester...@gmail.com>
> wrote:
>
>> 2015-02-14 12:33 GMT+01:00 Cecil Westerhof <cldwester...@gmail.com>:
>>
>>>
>>> 2015-02-11 8:32 GMT+01:00 Cecil Westerhof <cldwester...@gmail.com>:
>>>
>>>>
>>>> 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))
>>>>
>>>
> I don't understand why you prefer this over Phill's suggestion (using comp
> and having 3 versions of get-percentage). Then you wouldn't need the extra
> arity (2 param one) too.
>
> Phill's version is 7 lines of code, 4 simple defn's & 3 def's. I'm just
> saying this in case it was overlooked.
>

​One reason is that now I can use a parameter to decide which version to
call. If there is a part of code where the version of get-percentage is
depending on a parameter, I just can use:
    (get-percentage mode place total-count)

Instead of having to use a condition block at that place.

-- 
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.

Reply via email to