Re: Data manipulation question

2010-03-05 Thread Base
Wow - there are so many ways to skin a cat (and dog, bird, horse, wolf, and pig!) These are all great. Thank you all so so much James - I really appreciate walking me thru the methodology. that is a big help for those of us just gettting started (particularly when we dont have much lisp experie

Re: Data manipulation question

2010-03-05 Thread Tayssir John Gabbour
Yeah, on further reflection, I was just about to delete my message, as it annoyed me for a couple reasons. ;) The one you mentioned (which limits its reusability), and also the fact that my function does the mapping inside it. All the best, Tayssir On Mar 6, 1:54 am, Brendan Ribera wrote: > Or

Re: Data manipulation question

2010-03-05 Thread James Reeves
On Mar 5, 7:50 pm, James Reeves wrote: >   (apply map merge >     (for [k (keys m)] >       (for [v (.split (m k) " ")] >         {k v} On reflection, I think this should be (apply map merge (for [k (keys (first m))] (for [v (.split (m k) " ")] {k v}))) Also, this assumes each m

Re: Data manipulation question

2010-03-05 Thread Brendan Ribera
Or if you want something that is agnostic about the structure of your input map, try this: (defn alter-map [in-map] (map (partial reduce merge) (partition (count (keys in-map)) (apply interleave (map (fn [p] (map #(hash-map (first p)

Re: Data manipulation question

2010-03-05 Thread Mike Meyer
On Fri, 5 Mar 2010 16:07:55 -0800 (PST) Base wrote: > > Hi all - > > I am trying to transofrm a data structure and am kind of stuck. > > I currently have a list of maps > > ( {:animal "dog cat bird" :sound "woof meow chirp" :number-of-feet "4 > 4 2"} > {:animal "horse" :sound "ne" :numb

Re: Data manipulation question

2010-03-05 Thread James Reeves
When thinking about things functionally, it's useful to start from a basic case, and then work upward. For instance, we could start off by only transforming one key: (defn expand-map-key [m k] (for [v (.split (m k) " ")] {k v})) So: user=> (expand-map-key m :animal) ({:animal "d

Re: Data manipulation question

2010-03-05 Thread Tayssir John Gabbour
Hi Base, Perhaps something like the following: (defn normalize-creatures [creatures] (letfn [(split [str] (seq (.split str "\\s")))] (for [{:keys [animal sound number-of-feet]} creatures] (map (fn [a s n] {:animal a :sound s :number-of-feet n}) (split animal) (

Data manipulation question

2010-03-05 Thread Base
Hi all - I am trying to transofrm a data structure and am kind of stuck. I currently have a list of maps ( {:animal "dog cat bird" :sound "woof meow chirp" :number-of-feet "4 4 2"} {:animal "horse" :sound "ne" :number-of-feet "4"} {:animal "wolf pig" :sound "howl oink":number-of-feet "4