Hi Gomez, Thanks for your response. The goal was to implement the half_edge datastructure .. it is described here<http://www.flipcode.com/archives/The_Half-Edge_Data_Structure.shtml> . I felt using atoms was not going to serve any extra purpose .. What would you be doing in this situation... So googling actually led me to a previous post <http://www.mail-archive.com/[email protected]/msg25256.html>which discussed about the implementation of half-edge datastructure in clojure .. It gave a reference to this<http://www.cs.ucl.ac.uk/teaching/3C11/graph.pdf> publication.. But I just thought it might just be simpler to do a mutable thing while still taking advantage of clojures stuff outside of this data-structure.
Sunil. On Fri, Mar 18, 2011 at 7:08 PM, Daniel Solano Gomez <[email protected]>wrote: > On Fri Mar 18 18:33 2011, Sunil S Nandihalli wrote: > > I wanted to define a bunch of types which were mutable to be used in > > defining a cyclic data structure. So, I wrote the following macro... > > > > … code sample … > > > > although not idiomatic clojure .. thought some of you may find it useful. > > Sunil. > > Is there some reason you chose to use mutable members instead of one of > Clojure's concurrency primitives? From your example, it doesn't seem > like interop is the reason, given that your mutators will be called > something similar to ‘y__BANG__’. > > Also, given that you are defining both a protocol and a type where the > protocol doesn't seem like it really serves as an abstraction, perhaps > you would be better served with defrecord or just a plain old > map/struct. > > Here's an example using maps: > > (defn new-node [] > {:prev (atom nil) > :next (atom nil)}) > > (defn attach-next! [node next-node] > (reset! (:next node) next-node)) > > (defn next-node [node] > @(:next node)) > > This approach allows you to do some things you can't do with volatile > mutables, such as an atomic compare and set operation: > > (defn attach-next! [node next-node] > (compare-and-set! (:next node) nil next-node)) > > This function will only attach a next node if there is no next node > already. > > Sincerely, > > Daniel Solano Gómez > -- 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
