对于Ludum Dare 36
,我决定尝试使用基于文本的冒险游戏。它可以工作,但出现非致命错误:
线程“主”中的异常java.lang.ClassCastException:
seesaw.core.proxy $ javax.swing.JPanel $ Tag $ fd407141无法转换为
clojure.lang.IFn,
编译:(/ tmp / form-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错误在堆栈上有很多记录,但是我不确定哪个函数引起了该问题。也不确定我的代码质量。因此,请随时发表评论等。如何重构以消除Ifn错误?我不明白什么?
最佳答案
从第21行开始,在功能主体周围有额外的paren组; Clojure可能会认为您想调用(def...)
exp返回的函数可能是潜在原因。但这会导致一个Swing对象无法原样调用。