Very clear, much appreciate! On Jun 4, 2:55 am, Chouser <[email protected]> wrote: > On Thu, Jun 3, 2010 at 9:38 AM, YD <[email protected]> wrote: > > Hi, > > > When 'destructure' is doing a map destructuring, 'pmap' is the > > function to use. 'pmap' will do some kind of process to the given > > bindings using these lines of code: > > bes (reduce > > (fn [bes entry] > > (reduce #(assoc %1 %2 ((val > > entry) %2)) > > (dissoc bes (key > > entry)) > > ((key entry) bes))) > > (dissoc b :as :or) > > {:keys #(keyword (str %)), :strs > > str, :syms #(list `quote %)}) > > > I'm confused. Since every time ((key entry) bes) evaluates to nil, the > > inner reduce will never really do some useful thing. What's the > > purpose of this piece of code? > > Yes, if ((key entry) bes) is nil then the inner reduce simply > returns the binding map as it stands. The purpose of this code > is to support the :keys, :strs, and :syms keys in map > destructuring: > > (let [{:keys [a b]} {:a 1 :b 2}] [a b]) > ;=> [1 2] > > In this example, (key entry) will be :keys for one of the > iterations of the inner reduce. When (key entry) is :keys, ((key > entry) bes) will be [a b], and the inner reduce will process each > item of that vector, finally returning {a :a b :b} as the whole > binding map. > > Which means the above example does exactly the same things as: > > (let [{a :a b :b} {:a 1 :b 2}] [a b]) > ;=> [1 2] > > ...which is what you'd do if there was no support for :keys > > --Chouserhttp://joyofclojure.com/
-- 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
