【发布时间】:2023-04-07 05:01:01
【问题描述】:
我只是想在 Clojure 中写一个简单的小猜谜游戏,结果出现了这个错误。我看不到一个字符在哪里被视为我的函数,因为结果输入也预测不应该有这样的问题。代码如下:
(ns clojure.examples.hello
(:gen-class))
(ns clojure-noob.core)
(defn takeFst [x n]
(if (= n 0) () (cons (first x) (takeFst (rest x) (- n 1))))
)
(defn createSeq [elem n]
(if (= n 0) () (cons elem (createSeq elem (- n 1))))
)
(defn fnEquals? [n]
(fn [elem] (= elem n))
)
(defn removeEach [x elem]
(remove (fnEquals? elem) x)
)
(defn containsString? [s ch]
(not (empty? (filter true? (map = (createSeq ch (count s)) s))))
)
(defn akasztofa! [s lives]
(println s)
(if (and (not= () s) (not= lives 0))
(
(def guess (eval (read)))
(if (containsString? s guess) (akasztofa! (removeEach s guess) lives) (akasztofa! s (- lives 1)))
)
()
)
)
(akasztofa! "hab" 10)
我得到的输出是这样的:
hab
(a b)
(b)
()
Exception in thread "main" java.lang.ClassCastException:
java.lang.Character cannot be cast to clojure.lang.IFn, compiling:
(/home/cicaharcos/Documents/Clojure/First/akasztofa/main.clj:38:1)
我的输入是:\h \a \b
【问题讨论】: