BerlinBrown a écrit :
>
> On Jan 16, 11:10 am, BerlinBrown <[email protected]> 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.png summarizes 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---