As I am learning clojure, I am trying to build a simple tic tac toe game, without ia. I started with a method in order to show a board, but it seems very ugly to me : i am using internal functions, in order to make them local to the show-board method, so that it can't be instantiated outside. Perhaps the reason of the bad looking.
Here is the function (which works as I want) :
(defn show-board [board]
"Prints the board on the screen.
Board must be a list of three lists of three elements with
:cross for a cross and :circle for a circle, other value for nothing"
(let [convert-elem (fn [elem]
(cond
(= elem :cross) "X"
(= elem :circle) "O"
:other "_"))
convert-line (fn [elems-line]
(reduce str (map convert-elem elems-line)))]
(doseq [line board]
(println (convert-line line)))))
Here is a use case :
(show-board (list (list :cross :circle :none) (list :none :circle :none) (list :cross :none :none)))
Sorry for the ugly code, this is because I come from Java, and I am starting in Clojure. (I think I will really get benefits from learning Clojure, and make games with it, so I can't just leave it).
Another reason why I want to simplify it is for code maintenance and readability.
Thanks in advance