1
votes

For Ludum Dare 36 I decided to try a text based adventure game in coljure. It works, but I am getting a non-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))                                             

The Ifn error is fairly well documented on stack, but I am not sure which function is causing the issue. Also not sure on the quality of my code. So feel free to post comments etc. How can I refactor to get rid of the Ifn error? What do I not understand?

1
The line numbers are not part of your code; please remove them. - Sam Estep
What do you do with (button ...) at line 30? Without any possibility to run you code, this is the only suspect. If button is a wrapper around a widget, you will get that kind of exception - it's in the head position. Otherwise, attach the stacktrace and original source, the project file is also useful. - Yuri Steinschreiber
I think you might be right I get the error when I click. So if I move the button back maybe add an Ifn check it will help? - liminal18

1 Answers

2
votes

Starting on line 21 you have extra set of parens around the function body; it would be a potential cause for clojure to think you want to call up a function that's being returned by the (def...) exp. But that results in a Swing object that is not callable as is.