Home > clojure > A nice evening with the Clojure REPL

A nice evening with the Clojure REPL

April 25th, 2011 Leave a comment Go to comments

I’ve been working on Seesaw a lot lately. It’s a Swing wrapper/dsl/whatever for Clojure and I’ve had a great time working on it. Tonight, I was testing some very simple graphics stuff I added (namely, the (push) macro) and I had a nice moment with the REPL. Here’s my session where I paint some text to an image and display it in a JFrame:

Clojure
user=> (use 'seesaw.core)
nil
user=> (use 'seesaw.graphics)
nil
user=> (use 'seesaw.color)
nil
user=> (def image (buffered-image 200 200))
#'user/image
user=> (let [g (.getGraphics image)]
 (.setColor g (to-color "#FF0000"))
 (.drawString g "This is RED" 5 20)
 (push g
   (.setColor g (to-color "#0000FF"))
   (.drawString g "This is BLUE" 5 40))
 (.drawString g "This is RED again" 5 60))
nil
user=> (frame :content (label :icon image))
#<JFrame ...>
user=>

and up pops:

All the yucky Java-y graphics calls need to be cleaned up, but I would never be able to type in the equivalent code in Java without liberal use of ctrl+space.

Ok, back to work.

 

 

Categories: clojure Tags: ,
  1. April 27th, 2011 at 17:09 | #1

    REPLs are nice, no doubt. Have you seen Beanshell? — http://www.beanshell.org/home.html

    Back in 05 it passed JSR vote and then went quickly inactive, but was forked and AFAIK is fairly active (development) now at Beanshell2: http://code.google.com/p/beanshell2/

  2. April 28th, 2011 at 20:58 | #2

    Hey Jack! I’m aware of BeanShell, but never used it. Looks too much like writing Java to me :)

  3. limux
    May 7th, 2011 at 22:36 | #3

    I preferred to you will soon add the (.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE) as the frame’s default close behavior when one clicked the close button on the title.

  4. May 8th, 2011 at 08:36 | #4

    Are you using Seesaw? I’ve thought of adding that, but haven’t yet since I’m frequently using it from the REPL and exiting the JVM when I close the frame wouldn’t be desirable behavior.

  1. No trackbacks yet.