Re: Destructuring a seq of maps

2012-02-09 Thread Manuel Paccagnella
On 08/02/2012 03:05, Asim Jalis wrote: I frequently find myself passing around maps that are basically structs. I use this macro to destructure the fields into let variables. ; Macro. (defmacro def-fields [struct-name & fields] (let [field-symbol-vector (->> fields (map name) (map symbol) ve

Re: Destructuring a seq of maps

2012-02-07 Thread Asim Jalis
I frequently find myself passing around maps that are basically structs. I use this macro to destructure the fields into let variables. ; Macro. (defmacro def-fields [struct-name & fields] (let [field-symbol-vector (->> fields (map name) (map symbol) vec) arg (gensym) body (gens

Re: Destructuring a seq of maps

2012-02-07 Thread Manuel Paccagnella
On 02/07/2012 09:48 PM, Cedric Greevey wrote: One better way: (defn do-sum [some-coll] (reduce + (map :a some-coll))) Keywords can be used as functions. Sure! That's probably tidy enough not to feel the need to do something else, such as destructuring. Yes, I understa

Re: Destructuring a seq of maps

2012-02-07 Thread Cedric Greevey
On Tue, Feb 7, 2012 at 3:28 PM, Manuel Paccagnella wrote: > And let's say that I want a function that returns the sum of all :a values > of the something seq. I could write the function in this way: > >        (defn do-sum [some-coll] >          (reduce + (map #(:a %) some-coll))) > > Not a big de

Re: Destructuring a seq of maps

2012-02-07 Thread Manuel Paccagnella
On 02/07/2012 09:37 PM, Aaron Cohen wrote: Well, destructuring requires a literal, so you have to know exactly the structure you're wanting to pick apart. For your specific example, I can write a destructuring usage that will work, but there's no way to do it in a general way. user=>(defn do-sum

Re: Destructuring a seq of maps

2012-02-07 Thread Aaron Cohen
On Tue, Feb 7, 2012 at 3:28 PM, Manuel Paccagnella wrote: > I've some questions about destructuring a seq of maps, like: > > 1. Is it possible? > 2. If yes, does it have any sense? > 3. And if it's possible and is reasonable, how can I do it? > > For example, let&#

Destructuring a seq of maps

2012-02-07 Thread Manuel Paccagnella
I've some questions about destructuring a seq of maps, like: 1. Is it possible? 2. If yes, does it have any sense? 3. And if it's possible and is reasonable, how can I do it? For example, let's say that I have a list of maps like this: (def someth