Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread kurtharriger
I think you are too concerned with micro optimizations. get-in is probably just as efficient as attempting to bubble the state change back up and certainly simpler to work with. In practice, optimizations like this do not have a significant impact on the overall performace. Measure before yo

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread David Nolen
On Thu, Apr 26, 2012 at 5:08 PM, blais wrote: > I receive events from a network. My application calls for storing these > events and doing different things based on the changing status of orders > attached to these events. I need to store them somewhere, I need to track > this state in my app. At

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread blais
On Thursday, April 26, 2012 4:59:31 PM UTC-4, David Nolen wrote: > > On Thu, Apr 26, 2012 at 4:52 PM, blais wrote: > >> I suppose I could elect to move refs for modifiable things towards the >> leaves, but that seems to me like going against the grain and may have >> implications for concurrency

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread David Nolen
On Thu, Apr 26, 2012 at 4:52 PM, blais wrote: > I suppose I could elect to move refs for modifiable things towards the > leaves, but that seems to me like going against the grain and may have > implications for concurrency (there are few but some threads running in > parallel in this application)

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread blais
On Thursday, April 26, 2012 4:36:52 PM UTC-4, David Nolen wrote: > > On Thu, Apr 26, 2012 at 4:30 PM, blais wrote: > >> (Generally I find I get too little "cultural osmosis" when it comes to >> practical application of Clojure, so questions like this one come up all >> the time while I'm coding.

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread David Nolen
On Thu, Apr 26, 2012 at 4:30 PM, blais wrote: > (Generally I find I get too little "cultural osmosis" when it comes to > practical application of Clojure, so questions like this one come up all > the time while I'm coding. Meetups and books touch on topics I understand > well but rarely do people

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread blais
Thanks Andy, Two comments: 1. Your version does not use a transient/mutable, which is great, but it does create one vector for each level. I thought that since this would be wrapped and hidden from external view, a mutable would have been more appropriate. More generally, I still don't know ye

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread Jay Fields
I would have written the fn like this, if I was following what you've been doing: (def m {:planet {:country {:state {:city {:borough 4}) (let [mm (update-in m [:planet :country :state :city :borough ] (fnil inc -1))] (get-in mm [:planet :country :state :city :borough ])) However, when I ru

Re: (update-in) and getting the new value at the leaf efficiently

2012-04-26 Thread Andy Fingerhut
Here is one way to do it called update-in+. It returns a vector consisting of the new udpated value, like update-in does, followed by the original value (in case you might want to see that for some reason), followed by the updated value. (defn update-in+ ([m [k & ks] f & args] (if ks