On 13/06/12 11:21, Tassilo Horn wrote:
I don't get this. If you have your current-board as an atom containing
a collection of pieces, and every piece's location can be mutated by
(updatePosition piece ...), then doing that does change the world, i.e.,
the location of piece changed without having swap!-ed the atom.
aaa yes in that respect it does change it but it immediately builds a
new one and resets the atom with that.
If the things you store in atoms or refs aren't immutable, then the
guarantees made by those reference types simply don't apply.
hmmm...I see what you mean. I'll try to rethink my design... In fact, I
was wondering in the beggining of this project whether I need
java.awt.Point or not and I decided that I needed it cos I want to
eventually make a gui and a lot of methods in Swing take Point
args...I'll think about how else I can do it...
Does what you said mean that resetting or swapping the board atom will
not be atomic if the pieces have mutable state?
I guess I could leave Point as it is but instead of doing 'setLocation'
I can return a brand new Piece with a brand new Point...it will still be
mutable but there will be now way of mutating it...how does that sound?
No, you will have an atom containing a new board with new pieces in
their new position.
you mean making 32 new pieces after each move regardless of whether they
moved or not? how can I identify the ones that are different from the
ones that remain unchanged so i can conj them in a new list? move will
eventually call 'build-board' which has to look somewhere for the
current pieces. If moving a piece returns a new piece how do i associate
it with the previous board to produce the new? remember the piece has to
leave its current position and go the next one. That is one dissoc and
one assoc isn't it?
Jim
--
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