On Thu, Jul 9, 2009 at 7:31 AM, Patrik Fredriksson<patri...@gmail.com> wrote:
>
> My shot at a Clojure implementation, with inspiration from a previous
> post in this group on a similar problem:
>
> (ns step3.pnehm.clojure-orderer
>  (:gen-class
>    :name step3.pnehm.ClojureOrderer
>    :implements [pnehm.Orderer]
>    ))

Nice to see you're not intimidated by gen-class. :-)

> (defn cmpr [[val1 freq1] [val2 freq2]]
>  (let [freq (compare freq2 freq1)]
>    (if (not= freq 0) freq (compare val1 val2))))

When testing for equality with zero, it's more idiomatic and
sometimes faster to use 'zero?', so perhaps:

(if-not (zero? freq) freq (compare val1 val2))

> (defn -orderByFreq [_ coll]
>  (if (empty? coll) () (keys (sort cmpr (count-words coll)))))

Do you need to return an empty seq?  If not, how about:

(when (seq coll)
  (keys (sort cmpr (count-words coll))))

--Chouser

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

Reply via email to