I would like to share with you the joy of being able to finally make something working in Clojure.
This is a very simple program solving a very simple problem usually described in any IT University: palindrome detection.
My solution is not the most elegant and short one but it gave me the possibility to practice with Vectors.
Obviously any suggestion is more than welcome, thank you!
(defn is-letter [letter] (and (> (int letter) (int \A)) (< (int letter) (int \z)))) (defn check-palindrome ([word] (let [length (count (seq word)) letter-vector (vec (filter #(is-letter %1) (seq (.toUpperCase word))))] (check-palindrome letter-vector 0 (- (count letter-vector) 1) ) ) ) ([letters start end ] (cond (< end start) (Exception. "The string is NOT a palindrome") (not (= (letters start) (letters end))) (Exception. "The word is NOT a palindrome") (or (= start end) (= 1 (- end start))) (println "The string is a palindrome") :else (recur letters (inc start) (dec end))) ) ) (check-palindrome "Murder, for a jar of red rum")