对于Ludum Dare 36
我决定在coljure中尝试基于文本的冒险游戏。它有效,但我得到一个非致命的错误:
线程中的异常" main" java.lang.ClassCastException: seesaw.core.proxy $ javax.swing.JPanel $ Tag $ fd407141无法强制转换为 clojure.lang.IFn, 编译:(/ TMP /形状init2500875452880490300.clj:1:73)
(ns ludumdare36.core
(:gen-class :main true)
(:use seesaw.core))
(def story [
"Of all the most famous living rooms Transned's was the most famous"
"two"
"three"
"four"
"five"
"six"
"seven"
"eight"
"nine"
])
(def mainWindow (frame :title "Hello" :content "" :on-close :exit))
(defn draw
[items & args] (
(def mainWidget (vertical-panel :items items) )
(config! mainWidget :size [640 :by 480])
(config! mainWindow :content mainWidget)
(invoke-later(-> mainWindow pack! show!))))
(defn writeStory [text index & args]
(let [makeButton (fn mb [index text]
(button :text text :mnemonic \N :halign :center :listen [:action (partial writeStory (get story index) (inc index))]))
makeStoryNode (fn ms [text index]
(vector text (makeButton (inc index) "Yes") (makeButton (+ index 2 ) "No")))
]
(draw (makeStoryNode text index))))
(defn -main
[& args]
(writeStory (get story 0) 0))
堆栈上有很好的文档记录,但我不确定是哪个函数导致了这个问题。我也不确定我的代码的质量。所以随意发表评论等。如何重构以摆脱Ifn错误?我什么不明白?
答案 0 :(得分:2)
从第21行开始,你在函数体周围有一组额外的parens;这可能是clojure认为你想要调用(def...)
exp返回的函数的一个潜在原因。但是这会导致Swing对象无法按原样调用。