In your Java code,
getword is the only pure function: it takes a
string (w) and returns a string, with no side-effects on the external world. You're already fairly close to the Clojure equivalent:
You don't say what "many troubles" you are actually having so it's rather hard to help you.
I will note that your
transform2 function prints
x and returns the result of that
(prn x) call which will be
nil so that's probably tripping you up.
Also note that
for, like
map, is "lazy" and doesn't produce results unless you actually consume them with another function.
Going back to your Java code,
process() uses side-effects to achieve its goals, via the
map and
ws variables. Since your program processes a list (of strings) as input and produces a subset of those strings as output, the equivalent in Clojure could use
reduce in some way.
I
think your Java code is intended to produce the list of words that are unique when viewed as sorted, lower-case strings? Is that correct?
Something else to consider in Clojure is the
frequencies function which takes a collection and produces a hashmap from items to the number of occurrences (so
(frequencies (map get-word words)) would give you the occurrences for each lower-case, sorted
word in your original list of
words). Then you could transform that into a set of the items that only occur once, and use the set to filter the original words (something like
(filter #(unique-words (get-word %)) words) since a set can be used as a predicate).
I'll let you think about all that for a bit and if you're still stuck in a day or two, I'll show one possible solution (but there are many ways to solve this).