This is my first post here in the Clojure Forum.
I am currently trying to do my first steps in Clojure Programming by solving Clojure Koans.
Currently I ran into a problem while trying to complete a recursive pattern match on a string/ character list.
The main problem here seem to be type mismatches. However, the compiler output is not really helpful.
Any input or suggestions are appreciated!
Your if doesn’t have the else branch (check parentheses)
Check precisely what do you conj to rna (check parentheses, currently it looks like: ((str/replace...) (....) ...))
You intend to call str/replace 4 times in a row on the same input (remember, the last call will be returned). Possibly you want conditional replacement, check condp ((condp = (first dna) ...))
And last… there is a function for that! Try to find it in clojure.str namespace. One function to replace characters in given string: (str/... "CATG ...") ;; => "GUAC"
Ok, thank you!
I was partially able to follow your instructions.
Placing the parenthesis correctly around the else clause: Yes, I also had the idea this is wrong (double checked Russ Olson’s book “Getting Clojure”)
Instead of condp, I just made use of cond to achieve a simple pattern match.
I still would like to stick to the idea of recursion instead of jumping to a map function.
So here is an improved version, but there still seems to be a major pain-point:
A couple more comments… You are trying to call [first dna] as a function, with the results of your cond expression as arguments. That is almost certainly not what you want, and the compiler will complain, too.
Instead of repeating the (= (first dna) \...) bit, you could just do
Thank you for your reply!
Using a map / reduce function is of course another approach that is much more practicable. I will make use of these functions in the future. This time, I just wanted to stick to the recursive approach and finally got it to work.
I was finally able to solve it with a purely recursive approach!
Besides the wrong parenthesis around the else clause, my main problem was indeed proper handling of the string / character types.
The final fix I had to apply was a type conversion of the function input argument to string at the beginning of the loop (no idea why it was not a string to begin with)!
Now it looks like this: