On 10/01/14, Laurent PETIT wrote:
> What about this one?
> 
> Inspired by Stefan's, with more destructuring in loop, format-fn as a
> function, initial call to (seq) then (next) instead of (rest), placing the
> exit argument first so that it's not lost at the end of the function,
> renamed word as item since this function does not depend on the type of
> items.
> 
> (defn uniquify [in format-fn]
>   (loop [[item :as in] (seq in)
>          {n item :as item-nbrs} {}
>          out []]
>     (if-not in
>       out
>       (let [format-fn (if n format-fn (constantly item))]
>         (recur (next in)
>                (update-in item-nbrs [item] (fnil inc 0))
>                (conj out (format-fn item n)))))))

Yeah, that's better.  I like using `if-not` instead of `if` - it puts
the base case first, which I find preferable.  An adequate format
function can be given by defining a single-parameter version of
`uniquify`.
-- 
Stefan Kanev  ¦  @skanev  ¦  http://skanev.com/
Think of all the psychic energy expended in seeking a fundamental distinction
between "algorithm" and "program".

-- 
-- 
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/groups/opt_out.

Reply via email to