This is cool!

62 views
Skip to first unread message

Mathias Dahl

unread,
Oct 17, 2007, 2:33:29 PM10/17/07
to Clojure
I have started to experiment with this and have been able to figure
out how to do certain calls out to Java:

(. (. java.lang.System out) (println "Cool! Lisp in Java"))

=> Cool! Lisp in Java
nil

(new java.util.Date)

=> Wed Oct 17 20:01:38 CEST 2007

(. (new java.util.Date) (getTime))

=> 1192644138751

However, I did not get the example on the Getting Started page to
work. I tried to work it out myself but the following, which I would
guess should work, does not work:

=> (. (new javax.swing.JOptionPane) (showMessageDialog nil "one"
"two" (. javax.swing.JOptionPane ERROR_MESSAGE)))

java.lang.Exception: REPL:33: No matching method found
at clojure.lang.Compiler.analyzeSeq(Compiler.java:2535)
...

Pointers, anyone?

/Mathias

PS. First post! :)

Mathias Dahl

unread,
Oct 17, 2007, 2:39:39 PM10/17/07
to Clojure

> => (. (new javax.swing.JOptionPane) (showMessageDialog nil "one"
> "two" (. javax.swing.JOptionPane ERROR_MESSAGE)))
>
> java.lang.Exception: REPL:33: No matching method found
> at clojure.lang.Compiler.analyzeSeq(Compiler.java:2535)
> ...

My bad. That was a static method... This should work:

(. javax.swing.JOptionPane (showMessageDialog nil "one" "two" (.
javax.swing.JOptionPane ERROR_MESSAGE)))

But nothing happens. No error but I get no prompt back. Same with the
example on the intro page.

/Mathias

mago

unread,
Oct 17, 2007, 3:28:36 PM10/17/07
to Clojure
Try this:

user=> (.. System out (println "This is even cooler!"))
This is even cooler!
nil
user=>


:)

Stefan Lang

unread,
Oct 17, 2007, 4:10:02 PM10/17/07
to Clojure
Hello,

On 17 Okt., 20:39, Mathias Dahl <mathias.d...@gmail.com> wrote:

> My bad. That was a static method... This should work:
>
> (. javax.swing.JOptionPane (showMessageDialog nil "one" "two" (.
> javax.swing.JOptionPane ERROR_MESSAGE)))
>
> But nothing happens. No error but I get no prompt back. Same with the
> example on the intro page.

Works for me here, with java 1.6.0 on Linux. As well as the two arg
version:

(. javax.swing.JOptionPane (showMessageDialog nil "Hello, world!"))

mago

unread,
Oct 17, 2007, 4:16:19 PM10/17/07
to Clojure
It also works for me, with Java 1.5 on Mac OS X.

Stefan Lang

unread,
Oct 17, 2007, 4:17:45 PM10/17/07
to Clojure

On 17 Okt., 22:10, Stefan Lang <langste...@gmx.at> wrote:
> Hello,
>
> On 17 Okt., 20:39, Mathias Dahl <mathias.d...@gmail.com> wrote:
>
> > My bad. That was a static method... This should work:
>
> > (. javax.swing.JOptionPane (showMessageDialog nil "one" "two" (.
> > javax.swing.JOptionPane ERROR_MESSAGE)))
>
> > But nothing happens. No error but I get no prompt back. Same with the
> > example on the intro page.

Now I can reproduce your problem. It happens after I hit a cursor
key, which enters an escape sequence in my terminal, then hit Enter,
giving the exception "java.lang.Exception: Unable to resolve symbol:
in this context..."

Then when I try to show a dialog is behaves as you describe. In fact,
anything I enter afterwards just causes the REPL to hang. Seems to
mess up the reader or compiler.

Everything works again after restarting the REPL.

Mathias Dahl

unread,
Oct 17, 2007, 5:14:25 PM10/17/07
to Clojure

> Works for me here, with java 1.6.0 on Linux. As well as the two arg
> version:
>
> (. javax.swing.JOptionPane (showMessageDialog nil "Hello, world!"))

When testing at home, under GNU/Linux, it works for me as well. I
should have mentioned that the problem I had was under Windows XP.
Unsure of Java version, will check tomorrow.

Mathias Dahl

unread,
Oct 17, 2007, 5:15:47 PM10/17/07
to Clojure

> user=> (.. System out (println "This is even cooler!"))
> This is even cooler!
> nil
> user=>
>
> :)
>

Hehe :) Yes, I noticed after reading further in the manual... :) Neat!

Mathias Dahl

unread,
Oct 17, 2007, 5:20:38 PM10/17/07
to Clojure

> Now I can reproduce your problem. It happens after I hit a cursor
> key, which enters an escape sequence in my terminal

Speaking of terminals: I was a bit annoyed by the lack of line editing
(the cursor keys just output escape sequences for me too, under gnome-
terminal). Emacs to the rescue (as usual)! I started M-x shell and ran
Clojure from there. Instant hit! :) Completion, history et al.

Reply all
Reply to author
Forward
0 new messages