On Jan 16, 11:49 am, Christophe Grand <christo...@cgrand.net> wrote:
> BerlinBrown a écrit :
>
> > On Jan 16, 11:10 am, BerlinBrown <berlin.br...@gmail.com> wrote:
>
> >> I am working on this GUI tool and want to keep 'global' data
> >> structures in memory. For example, lets say I have a checkbox and
> >> want to be able to keep and access the state of that checkbox at any
> >> time. Right now, I am thinking the easiest thing to do is using a
> >> Java hashmap and change the state when needed.
>
> > Should I use 'ref' or 'agent' to do this?
>
> Yes!http://clojure.googlegroups.com/web/clojure-conc.pngsummarizes the
> differences between atoms, refs and agents.
> (and the fine doc tells you the details.)
>
> I think you need an atom or a ref:
>
> (def my-map (ref {:checkbox-state false}))
>
> (defn get-checkbox-state []
> (@my-map :checkbox-state))
>
> (defn set-checkbox-state [state]
> (dosync (commute my-map assoc :checkbox-state state)))
>
> Christophe
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))))))))
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---