gpt4 book ai didi

java.swing 无法转换为 clojure Ifn

转载 作者:行者123 更新时间:2023-11-30 02:49:05 26 4
gpt4 key购买 nike

对于 Ludum Dare 36,我决定在 coljure 中尝试基于文本的冒险游戏。它有效,但我收到一个非 fatal error :

Exception in thread "main" java.lang.ClassCastException: seesaw.core.proxy$javax.swing.JPanel$Tag$fd407141 cannot be cast to clojure.lang.IFn, compiling:(/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 行开始,函数体周围有一组额外的括号;这可能是 clojure 认为您想要调用由 (def...) exp 返回的函数的潜在原因。但这会导致 Swing 对象无法按原样调用。

关于java.swing 无法转换为 clojure Ifn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39274294/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com