--
--
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
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
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.
For more options, visit https://groups.google.com/groups/opt_out.
I have a sequence of file names and I want to make them unique. (uniquify ["a" "b" "c" "a"]) => ["a" "b" "c" "a_1"])This is what I have come up with, but surely there is a better way?
--
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+unsubscribe@googlegroups.com.
--
--
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
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
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.
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.
--
Stefan Kanev Ś @skanev Ś http://skanev.com/
Giving up on assembly language was the apple in our Garden of Eden: Languages
whose use squanders machine cycles are sinful. The LISP machine now permits
LISP programmers to abandon bra and fig-leaf.
--
--
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
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
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/rt-l_X3gK-I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.
That's why I wrote my solution like I did, i.e., concatenate "_1" when a new string is found. This would result in the vector ["a_1" "a_2" "a_1_1"]
Hi,Use frequencies to get a map of path => nb of occurrences, then for each entry of the map, create unique names.Cannot provide an impl on the uPhine, sorry
Being really anal I could claim the original a_2 should remain a_2 and the third instance of a jump to being a_3.
--
--
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
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
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.
I have a sequence of file names and I want to make them unique. (uniquify ["a" "b" "c" "a"]) => ["a" "b" "c" "a_1"])This is what I have come up with, but surely there is a better way?What would you all do? Feedback welcome (including the word 'muppet' as I am sure I have missed something simple) :)
(defn uniquify"Return a sequence, in the same order as s containing every elementof s. If s (which is presumed to be a string) occurs more than oncethen every subsequent occurrence will be made unique.Items will be updated to include an incrementing numeric count usingthe specified formatter function. The formatter function will begiven the name and the number and should return a combination of thetwo.The set of unique s's in the returned sequence will be the count ofs's in s."
([s] (uniquify s (fn [item duplicates] (str item "_" duplicates))))([s formatter]
(let [occurrences (atom {})register-occurrence (fn [item](if (get @occurrences item)(swap! (get @occurrences item) inc)(swap! occurrences assoc item (atom 1)))@(get @occurrences item))process (fn [item](let [duplicates (dec (register-occurrence item))](if (> duplicates 0)(formatter item duplicates)item)))unique-s (map process s)]unique-s)))
--