An atom seems appropriate after reading up on it, but documentation
seems a little scarce.  Reading about atoms on the clojure site gives
a very small example using just a {}.  I've tried piecing it together
using a struct but am getting

Exception in thread "main" java.lang.IllegalArgumentException: Key
must be integer (start.clj:0)

Can atoms be only certain types?

let [context (atom (create-context))] ; create-context returns a context object
  (def canvas0 (create-canvas 0 context)) ; passing the atomized
context to a struct
  )


On Sat, Mar 20, 2010 at 8:51 AM, Mike Meyer
<[email protected]> wrote:
> On Sat, 20 Mar 2010 08:11:49 -0700 (PDT)
> strattonbrazil <[email protected]> wrote:
>
>> I'd like to separate my ui Swing/JOGL from the content, so my code is
>> relatively unaware of the UI around it.  For example, I create a
>> global context that holds on my content.  I then make a UI that when
>> the user does some interaction like a mouse click or drag, the UI
>> creates a new context.  My OO instincts would be to create a context
>> and pass it to all my UI objects that receive events and mutate them,
>> but if I'm dealing with an immutable class if I pass it to each UI
>> object, when one UI object makes a new context, it isn't reflected in
>> the other UIs.  Basically I want all UIs pointing to the same context
>> and each UI being able to create a new context that each UI points
>> to.  It seems that when one UI updates the global context reference
>> with a 'def', the others are still using the old one.
>
> You need to update shared data, and that doesn't seem avoidable. In
> clojure, you do that with either a ref or an atom holding the data,
> depending on how you need to update it. This will make it thread safe
> if/when you start running your UI objects in different threads.
>
>     <mike
>
> --
> Mike Meyer <[email protected]>              http://www.mired.org/consulting.html
> Independent Network/Unix/Perforce consultant, email for more information.
>
> O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your 
> first post.
> 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
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to