Hi Berlin, Probably ref, if the state must be coordinate with other state, or atom, if it is totally independent. But you might be able to avoid using mutable state at all. We would need a larger example to tell.
Stuart > 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. >> >> (def my-map (new HashMap)) >> >> (defn init-hash-map [] >> (. my-map put "checkbox-state" "false")) >> >> (defn get-checkbox-state [] >> (. my-map get "checkbox-state")) >> >> ... >> ... >> >> Is this bad clojure or lisp code (probably is), but what are some >> other approaches? > > I hear that in Erlang, you can use processes to work with mutable > state. And some say that Clojure has some similar functionality. > Should I use 'ref' or 'agent' to do this? > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---