My take: 2011/4/13 babui <jmgim...@gmail.com>
> I have a project in which I have to use some java mutable objects > (e.g. a graph). > > In my code, I have some functions that get these objects and add nodes > to them, for instance: > > (defn make-graph [] .... returns a graph wrapped with other things) > > (defn add-to-graph [graph n] .... adds n to the structure ...) > > In order to use the threading macro -> I have done that all functions > returns the mutated graph, so I can write: > > (def my-graph (-> (make-graph) > (add-to-graph 1 2 3) > (add-to-graph 4 5 6) > ....)) > > But as convenient as this is, I think its misleading and inelegant > because -> is a functional threading. I feel I need some king of doto > but fir clojure code. Something like: > > (def my-graph (make-graph)) > > (doto mygraph > (add-to-graph! 1 2 3) > (add-to-graph! 4 5 6)) > Doing so would lead to less generic code: if some day you want (make-graph) to create a persistent datastructure representing the graph, doto version will need to be rewritten into my-graph. Maybe having the threaded version, but with an emphasis on the mutation on the add-to-graph! via the bang at the end ? So you'll have the code structure right, and changing the persistent datastructure would imply a simpler refactoring: change the name add-to-graph! into add-to-graph ... (that is, use a functional style as for transients) > > Is this a valid concern or I am overzealous over this? > > Thanks. > > Juan Manuel > > -- > 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 -- 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