Re: Regarding The Implementation of 'merge-with'

2011-01-20 Thread Stefan Rohlfing
Hi John, Thanks for your detailed explanation of the inner workings of my code! I have been confused by the behavior of Clojure's mutable data structures quite often, but after reading your explanation it finally starts to make sense. I also tried to explain why your code works: Everything

Re: Regarding The Implementation of 'merge-with'

2011-01-20 Thread John Szakmeister
On Thu, Jan 20, 2011 at 3:34 AM, Stefan Rohlfing wrote: > Hi John, > Thank you very much for your correction of my code! my-merge-with is working > perfectly now. > There is just one thing: I always want to understand my errors so that I can > learn from them. However, I still don't understand why

Re: Regarding The Implementation of 'merge-with'

2011-01-20 Thread Stefan Rohlfing
Hi John, Thank you very much for your correction of my code! *my-merge-with* is working perfectly now. There is just one thing: I always want to understand my errors so that I can learn from them. However, I still don't understand why my implementation did not work. Looking at my code I am thi

Re: Regarding The Implementation of 'merge-with'

2011-01-20 Thread John Szakmeister
On Wed, Jan 19, 2011 at 11:23 PM, Stefan Rohlfing wrote: > Hi all, > > I tried another implementation of 'merge-with' using nested calls to > 'reduce'. However, > I just cannot get it to work correctly: > > (defn my-merge-with [f & maps] >  (when (some identity > maps) >    (reduce >     (fn [acc

Re: Regarding The Implementation of 'merge-with'

2011-01-19 Thread Stefan Rohlfing
Hi all, I tried another implementation of 'merge-with' using nested calls to 'reduce'. However, I just cannot get it to work correctly: (defn my-merge-with [f & maps] (when (some identity maps) (reduce (fn [acc m] (reduce (fn [_ [key val]] (assoc acc key (if-le

Re: Regarding The Implementation of 'merge-with'

2010-11-26 Thread Daniel Werner
On 26 November 2010 16:48, Laurent PETIT wrote: > 2010/11/26 Steven E. Harris >> Daniel Werner writes: >> > (some identity maps), on the other hand, checks whether there is any >> > non-empty map *in the coll of maps*. >> >> By "non-empty" here, do you really mean non-nil? I don't see how the >>

Re: Regarding The Implementation of 'merge-with'

2010-11-26 Thread Laurent PETIT
2010/11/26 Steven E. Harris > Daniel Werner writes: > > > (some identity maps), on the other hand, checks whether there is any > > non-empty map *in the coll of maps*. > > By "non-empty" here, do you really mean non-nil? I don't see how the > identity function would tell you whether any of the m

Re: Regarding The Implementation of 'merge-with'

2010-11-26 Thread Steven E. Harris
Daniel Werner writes: > (some identity maps), on the other hand, checks whether there is any > non-empty map *in the coll of maps*. By "non-empty" here, do you really mean non-nil? I don't see how the identity function would tell you whether any of the maps are empty or not. -- Steven E. Harri

Re: Regarding The Implementation of 'merge-with'

2010-11-26 Thread Daniel Werner
On Nov 26, 1:42 pm, Stefan Rohlfing wrote: > Question 1: > (when (some identity maps) > > This expression from the original implementation checks if the > provided coll is empty. > However, why not just use (when (empty? maps) or (when (seq maps) > instead? Note also that (seq maps) and (empty? m

Re: Regarding The Implementation of 'merge-with'

2010-11-26 Thread Stefan Rohlfing
Hi Chris, Thanks a lot for your clear explanations! Now all the pieces suddenly make sense to me. Stefan On Nov 26, 9:30 pm, Chris Perkins wrote: > On Nov 26, 7:42 am, Stefan Rohlfing wrote: > > > > > > > > > > > Dear Clojure Group, > > > Today I took a closer look at the 'merge-with' function

Re: Regarding The Implementation of 'merge-with'

2010-11-26 Thread Chris Perkins
On Nov 26, 7:42 am, Stefan Rohlfing wrote: > Dear Clojure Group, > > Today I took a closer look at the 'merge-with' function of Clojure > Core and changed some parts to better understand its implementation. > > Now I still have two questions regarding the following code: > > (defn my-merge-with [f

Regarding The Implementation of 'merge-with'

2010-11-26 Thread Stefan Rohlfing
Dear Clojure Group, Today I took a closer look at the 'merge-with' function of Clojure Core and changed some parts to better understand its implementation. Now I still have two questions regarding the following code: (defn my-merge-with [f & maps] (when (some identity maps)