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 starts with an empty map of *acc* that is bound to *acc2* (the
accumulator of the inner reduce):
;; Inner reduce
(assoc {} :a 1) ;; --> {:a 1}
(assoc {:a 1} :b 2) ;; --> {:a 1 :b 2}
;; This map is then returned to the outer reduce and bound again to *acc2*
;; In the next step *acc* will again be the start map for the inner reduce:
;; Inner reduce
(assoc {:a 1 :b 2} :a (+ 1 9)) ;; --> {:a 10, :b 2}
(assoc {:a 10, :b 2} :b (+ 2 98)) ;; --> {:a 10, :b 100}
(assoc {:a 10, :b 100} :c 0) ;; --> {:c 0, :a 10, :b 100}
Best regards,
Stefan
--
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