Clojure Defn 在显示正确答案后返回空括号
Clojure Defn returning empty parentheses just after displaying correct answer
我试图只获取一个生肖名称以将其传递给不同的函数,但我不知道为什么我在显示生肖后会得到空括号。我是 Clojure 新手。
(defn miko []
(let [guess (read)]
(remove nil?(cond
(some #(= guess %) (range 101 120))(println "Capricorn")
(some #(= guess %) (range 120 219))(println "Aquarius")
(some #(= guess %) (range 219 321))(print "Pisces")
(some #(= guess %) (range 321 420))(print "Aries")
(some #(= guess %) (range 420 521))(print "Taurus")
(some #(= guess %) (range 521 621))(print "Gemini")
(some #(= guess %) (range 621 723))(print "Cancer")
(some #(= guess %) (range 723 823))(print "Leo")
(some #(= guess %) (range 823 923))(print "Virgo")
(some #(= guess %) (range 923 1023))(print "Libra")
(some #(= guess %) (range 1023 1122))(print "Scorpio")
(some #(= guess %) (range 1122 1221))(print "Sagittarius")
(some #(= guess %) (range 1221 3112))(print "Capricorn")
:else "wrong"))))
I run it (miko) and this is the result:
Capricorn
()
请帮我删除这个,因为当我想将结果名称(例如 Capricorn)传递给另一个函数时,它会传递给 ()-括号。
你做的很好,只需删除打印语句,例如将 (print "Capricorn")
替换为 "Capricorn"
,该功能将起作用。
你也不需要 (remove nil? ...)
我试图只获取一个生肖名称以将其传递给不同的函数,但我不知道为什么我在显示生肖后会得到空括号。我是 Clojure 新手。
(defn miko []
(let [guess (read)]
(remove nil?(cond
(some #(= guess %) (range 101 120))(println "Capricorn")
(some #(= guess %) (range 120 219))(println "Aquarius")
(some #(= guess %) (range 219 321))(print "Pisces")
(some #(= guess %) (range 321 420))(print "Aries")
(some #(= guess %) (range 420 521))(print "Taurus")
(some #(= guess %) (range 521 621))(print "Gemini")
(some #(= guess %) (range 621 723))(print "Cancer")
(some #(= guess %) (range 723 823))(print "Leo")
(some #(= guess %) (range 823 923))(print "Virgo")
(some #(= guess %) (range 923 1023))(print "Libra")
(some #(= guess %) (range 1023 1122))(print "Scorpio")
(some #(= guess %) (range 1122 1221))(print "Sagittarius")
(some #(= guess %) (range 1221 3112))(print "Capricorn")
:else "wrong"))))
I run it (miko) and this is the result:
Capricorn
()
请帮我删除这个,因为当我想将结果名称(例如 Capricorn)传递给另一个函数时,它会传递给 ()-括号。
你做的很好,只需删除打印语句,例如将 (print "Capricorn")
替换为 "Capricorn"
,该功能将起作用。
你也不需要 (remove nil? ...)