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
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
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
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
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
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
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