Meu código está assim:
(def max-number-lifes 6)
(declare game)
(defn game-over [message]
(do
(println message)
(System/exit 0)
)
)
(defn lost [] ((game-over "You were hang!")))
(defn won [] (game-over "Congrats, you discovered the word!"))
(defn missing-letters [word guesses]
(remove (fn [letter] (contains? guesses (str letter))) word)
)
(defn was-word-guessed? [word guesses]
(empty? (missing-letters word guesses))
)
(defn read-letter! [] (read-line))
(defn is-guess-right? [word guess] (.contains word guess))
(defn game [lifes word guesses] (
(cond
(= lifes 0) (lost)
(was-word-guessed? word guesses) (won)
:else
(let [guess (read-letter!)]
(if (is-guess-right? word guess)
(do
(println "You guessed right!!")
(recur lifes word (conj guesses guess)))
(do
(println "You guessed was wrong. You lost one life")
(recur (dec lifes) word guesses)))))))
O porblem é que quando executo ele recebo a excessão
#error {
:cause Can only recur from tail position
:via
[{:type clojure.lang.Compiler$CompilerException
:message Syntax error compiling recur at (hangman/core.clj:38:42).
:data #:clojure.error{:phase :compile-syntax-check, :line 38, :column 42, :source hangman/core.clj, :symbol recur}
:at [clojure.lang.Compiler analyzeSeq Compiler.java 7114]}
{:type java.lang.UnsupportedOperationException
:message Can only recur from tail position
:at [clojure.lang.Compiler$RecurExpr$Parser parse Compiler.java 6662]}]
:trace
Como meu código está exatamente com a causa dupla conforme o video, não consegui entender o porquê do erro.