Hi all,

I'm new to Clojure and I'm playing around with Qt Jambi, which works
as expected, until I started to use a self written macro. Now I don't
know if this is just a problem I don't see (probably) or if it is a
bug in Clojure. I have the following sample code (I hope this is
readable when posted. Otherwise I'll use something like pastebin):


> (ns a.namespace.sample
>   (:gen-class)
>   (:import
>      (com.trolltech.qt.gui QApplication QMainWindow)))
>
> (defmacro RunQt [args & body]
>   `(
>     (try
>       (QApplication/initialize (into-array [~args]))
>       (catch RuntimeException e# (println e#)))
>     ~...@body
>     (QApplication/exec)))
>
>
> (defn -main [args]
>   (RunQt args
>     (let [mainWindow (QMainWindow.)]
>       (.show mainWindow))))
>
> (defn -main2 [args]
>   (try
>     (QApplication/initialize (into-array [args]))
>     (catch RuntimeException e (println e)))
>   (let [mainWindow (QMainWindow.)]
>     (.show mainWindow))
>   (QApplication/exec))
>
>
> ; (-main "")
> ; (-main2 "")


Now both -main and -main2 work as expected, they show a simple Window
with nothing in it. So far so good. But after I close the Window, -
main throws the following exception:

> Exception in thread "main" java.lang.NullPointerException (qtest.clj:0)
>         at clojure.lang.Compiler.eval(Compiler.java:4543)
>         at clojure.lang.Compiler.load(Compiler.java:4857)
>         at clojure.lang.Compiler.loadFile(Compiler.java:4824)
>         at clojure.main$load_script__5833.invoke(main.clj:206)
>         at clojure.main$script_opt__5864.invoke(main.clj:258)
>         at clojure.main$main__5888.doInvoke(main.clj:333)
>         at clojure.lang.RestFn.invoke(RestFn.java:413)
>         at clojure.lang.Var.invoke(Var.java:346)
>         at clojure.lang.AFn.applyToHelper(AFn.java:173)
>         at clojure.lang.Var.applyTo(Var.java:463)
>         at clojure.main.main(main.java:39)
> Caused by: java.lang.NullPointerException
>         at a.namespace.sample$_main__8.invoke(qtest.clj:16)
>         at a.namespace.sample$eval__20.invoke(qtest.clj:29)
>         at clojure.lang.Compiler.eval(Compiler.java:4532)
>         ... 10 more


whereas -main2 does not. Now they both look to my newbie eyes the
same, except the code of -main is generated by a macro. This is the
same if I compile the code. The uncompiled version I started with
(paths omitted for better readability):

> java -cp clojure.jar;qtjambi-4.5.2_01.jar;qtjambi-win32-msvc2005-4.5.2_01.jar 
> clojure.main qtest.clj


I have this behavior under WinXP and 2k, with Java RE 1.5.x and with
JDK 1.6.0_16, Clojure 1.0.0 and the latest Qt Jambi. Am I just missing
something totally fundamental and this is expected behavior? I fiddled
with this code for I don't know how long, tried this and that but
cannot figure out where this NullPointerException is coming from.

Any help would be appreciated.


Thanks and greetings....

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to