The only thing I might change is the way you are incrementing the counter:
(defn counter-animation [running counter] (when running (send-off *agent* counter-animation (+ counter 1))) (println counter) (. Thread sleep 500) running) (defn start-animation [] (send animator (fn [x] true));should this be send-off? why? (send-off animator counter-animation 0)) Will do the same thing but every run will start from 0 (rather than re-defining the global counter variable every time). Eric Tschetter On Fri, Apr 3, 2009 at 8:05 PM, Curran Kelleher <curran.kelle...@gmail.com> wrote: > > Hi all, > > I'm trying to get started with an OpenGL (JOGL) application in > Clojure, and one of the first orders of business is establishing a > thread that repeatedly calls the display function - the game loop. I'm > not sure what the idiomatic way to do this in Clojure is. > > The below code works, but is it good Clojure style and lightweight > enough for a game loop running at ~60 fps? I would greatly appreciate > any tips! > > ;;Prints incrementing integers every 500 ms in a separate thread > ;is this the Clojure way? > (def counter 0) > (def animator (agent false));agent state = running flag > (defn animation [running] > (when running > (send-off *agent* #'animation)) > (def counter (+ 1 counter)) > ; (set! counter (+ 1 counter)) <-- just doesn't work! > (println counter) > (. Thread sleep 500) > running) > > (defn start-animation [] > (send animator (fn [x] true));should this be send-off? why? > (send-off animator animation)) > > (defn stop-animation [] > (send animator (fn [x] false))) > > ;for SLIME > (comment > (start-animation) > (stop-animation) > ) > > Thanks a lot! Clojure is a blast! > > Best, > Curran Kelleher > > > --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---