Re: referencing an atom inside a function used for swapping

2010-03-26 Thread Meikel Brandmeyer
Hi,

construct the JPanel outside the atom, add all the listeners and then
add the panel to structure in the atom.

(let [panel (JPanel. ..)]
  (add-listener-stuff panel the-atom)
  (swap! the-atom assoc :SpiffyPanel panel))

Side-effecting things shouldn't be done inside the swap! since it can
be retried multiple times. So you would set up a panel, find that you
have to retry, start over, retry, start over, retry, 

Sincerely
Meikel

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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

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


Re: referencing an atom inside a function used for swapping

2010-03-26 Thread Josh Stratton
 construct the JPanel outside the atom, add all the listeners and then
 add the panel to structure in the atom.

 (let [panel (JPanel. ..)]
  (add-listener-stuff panel the-atom)
  (swap! the-atom assoc :SpiffyPanel panel))

 Side-effecting things shouldn't be done inside the swap! since it can
 be retried multiple times. So you would set up a panel, find that you
 have to retry, start over, retry, start over, retry, 

Okay, I'll add the panel outside.  But I don't think this is really a
side effect.  The events that call swap won't be called inside the
function that is creating the panel since they're event listeners.
Thanks.

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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

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


Re: referencing an atom inside a function used for swapping

2010-03-25 Thread Mark J. Reed
I would just pass the atom and move the @ inside the function...

On Thursday, March 25, 2010, strattonbrazil strattonbra...@gmail.com wrote:
 I have a function that I use for adding a JPanel to a ui atom.  When I
 call swap! that ui atom is sent to that function I call with the swap!
 on and is dereferenced inside the function so I don't need to call @ui
 on it.  However, I want to add listeners to my JPanel that can affect
 that atom, but I don't have the actual atom anymore since it's
 deferenced when I pass it to swap.  I believe I could just pass it as
 another parameter, but that seems like a hack.

 (defn swap-function [ui atomWithUiInIt]

       ; add code that on a click or press or something, alter the
 atomWithUiInIt atom
    ...)

 Is there better way to handle 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
 Note that posts from new members are moderated - please be patient with your 
 first post.
 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

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


-- 
Mark J. Reed markjr...@gmail.com

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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

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


Re: referencing an atom inside a function used for swapping

2010-03-25 Thread Josh Stratton
 I would just pass the atom and move the @ inside the function...

But the non-atom is automatically dereferenced and sent to the
respective function when I use swap!  So unless there's another
function to alter atoms, I'm going to have the dereferenced version
there no matter what, right?


 On Thursday, March 25, 2010, strattonbrazil strattonbra...@gmail.com wrote:
 I have a function that I use for adding a JPanel to a ui atom.  When I
 call swap! that ui atom is sent to that function I call with the swap!
 on and is dereferenced inside the function so I don't need to call @ui
 on it.  However, I want to add listeners to my JPanel that can affect
 that atom, but I don't have the actual atom anymore since it's
 deferenced when I pass it to swap.  I believe I could just pass it as
 another parameter, but that seems like a hack.

 (defn swap-function [ui atomWithUiInIt]

       ; add code that on a click or press or something, alter the
 atomWithUiInIt atom
    ...)

 Is there better way to handle 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
 Note that posts from new members are moderated - please be patient with your 
 first post.
 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

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


 --
 Mark J. Reed markjr...@gmail.com

 --
 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
 Note that posts from new members are moderated - please be patient with your 
 first post.
 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

 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 clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
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

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


Re: referencing an atom inside a function used for swapping

2010-03-25 Thread Mark J. Reed
Ah, right, this is the function called from swap!.  So move the
listener stuff out of your swap function and into the function that
calls swap! instead?

On Thu, Mar 25, 2010 at 11:02 PM, Josh Stratton
strattonbra...@gmail.com wrote:
 I would just pass the atom and move the @ inside the function...

 But the non-atom is automatically dereferenced and sent to the
 respective function when I use swap!  So unless there's another
 function to alter atoms, I'm going to have the dereferenced version
 there no matter what, right?


 On Thursday, March 25, 2010, strattonbrazil strattonbra...@gmail.com wrote:
 I have a function that I use for adding a JPanel to a ui atom.  When I
 call swap! that ui atom is sent to that function I call with the swap!
 on and is dereferenced inside the function so I don't need to call @ui
 on it.  However, I want to add listeners to my JPanel that can affect
 that atom, but I don't have the actual atom anymore since it's
 deferenced when I pass it to swap.  I believe I could just pass it as
 another parameter, but that seems like a hack.

 (defn swap-function [ui atomWithUiInIt]

       ; add code that on a click or press or something, alter the
 atomWithUiInIt atom
    ...)

 Is there better way to handle 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
 Note that posts from new members are moderated - please be patient with 
 your first post.
 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

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


 --
 Mark J. Reed markjr...@gmail.com

 --
 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
 Note that posts from new members are moderated - please be patient with your 
 first post.
 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

 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 clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 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

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




-- 
Mark J. Reed markjr...@gmail.com

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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

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