java.swing不能转换为Clojure Ifn

java.swing can not be cast to clojure Ifn

对于Ludum Dare 36,我决定尝试使用基于文本的冒险游戏。它可以工作,但出现非致命错误:

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)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(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 \
 :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返回的函数,这可能是clojure的潜在原因。但这会导致无法按原样调用Swing对象。