I’m trying to go through the problem set at 4clojure.org. I’m on number 23 (reverse a string without using ‘reverse’ function). I’m getting this error:
Don’t know how to create ISeq from: java.lang.Long
here’s my code:
(fn rev [coll]
(if (= () coll)
nil
((cons(rev (rest coll))(first coll)))))
edited now to this:
(fn rev [coll]
(if (empty? coll)
coll
(concat(rev (rest coll))((list first coll)))))
presumably this is from trying to cons the head of the sequence to the end of the rest of the sequence.
What’s the right way of doing this?
This error is because you are trying to
consaseqto an element rather than an element to aseq. In other words, your arguments toconsare in the wrong order. But, if you corrected the order, you’d just be piecing a list back together in the same order.Using the same general idea you have, you could turn the second argument into a list by wrapping it in
(list ...)and thenconcatthe two lists together:You’ll discover more concise solutions as you go along.