This and Jonas' are my current favourites, for what that's worth.

Keep the suggestions coming! 

On Friday, 10 January 2014 17:29:20 UTC, 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)))))))
>
>
> 2014/1/10 Laurent PETIT <lauren...@gmail.com <javascript:>>
>
>> no you have a bug in this last version, it now skips the last result
>>
>>
>> 2014/1/10 Stefan Kanev <stefan...@gmail.com <javascript:>>
>>
>>> Somehow I totally forgot I could use destructuring.  Here's a slightly
>>> shorter version:
>>>
>>>     (defn uniquify [words]
>>>       (loop [encountered {}
>>>              result []
>>>              [word & remaining] words]
>>>         (if (seq remaining)
>>>           (let [occurences (get encountered word)
>>>                 modified (if occurences
>>>                            (str word "_" occurences)
>>>                            word)]
>>>             (recur (update-in encountered [word] (fnil inc 0))
>>>                    (conj result modified)
>>>                    remaining))
>>>           result)))
>>>
>>> --
>>> Stefan Kanev  ¦  @skanev  ¦  http://skanev.com/
>>> You can measure a programmer's perspective by noting his attitude on the
>>> continuing vitality of FORTRAN.
>>>
>>> --
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@googlegroups.com<javascript:>
>>> Note that posts from new members are moderated - please be patient with 
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> clojure+u...@googlegroups.com <javascript:>
>>> 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+u...@googlegroups.com <javascript:>.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>
>

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