On Fri, Jan 16, 2009 at 12:13 PM, BerlinBrown <berlin.br...@gmail.com> wrote: > > On Jan 16, 12:47 pm, Christophe Grand <christo...@cgrand.net> wrote: >> BerlinBrown a écrit : >> >> > Thanks all, this is what I ended up with: >> > For noobs like myself, I am using this code to monitor files and >> > refresh it when the file gets modified. I used 'ref' and 'agent'. >> >> > (def file-monitor-agent (agent false)) >> > (def file-state (ref {:open-state false})) >> > (defn get-file-state [] (@file-state :open-state)) >> > (defn set-file-state [state] (dosync (commute file-state assoc :open- >> > state state))) >> >> > (defn file-monitor-loop [] >> > (let [delay-t (prop-int resources-core-sys >> > "Octane_Sys_filemonitor_delay") >> > enable-file-mon (prop-bool resources-win-opts >> > "file_monitor_enabled")] >> > (send file-monitor-agent >> > (fn [_] >> > (when enable-file-mon >> > (loop [] >> > (when (not (. shell (isDisposed))) >> > (. Thread sleep delay-t) >> > (println "Woot!!!") >> > (recur)))))))) >> >> Since the action you send to your agent doesn't end you should send it >> using send-off ('send-off will give your action its own thread while >> 'send use a fixed thread pool). >> But, given that you don't care about the agent value, it would be better >> to simply use a thread (clojure's fns are Runnables): >> >> (defn file-monitor-loop [] >> (let [delay-t (prop-int resources-core-sys >> "Octane_Sys_filemonitor_delay") >> enable-file-mon (prop-bool resources-win-opts >> "file_monitor_enabled")] >> (when enable-file-mon >> (.start (Thread. >> #(while (not (.isDisposed shell)) >> (Thread/sleep delay-t) >> (println "Woot!!!"))))))) >> >> Christophe > > What is the '#' in this example.
It's the beginning of the definition of an anonymous function. That's what is passed to the Thread constructor. -- R. Mark Volkmann Object Computing, Inc. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---