Re: constructing maps

2009-05-05 Thread Nathan Hawkins
On Tue, 05 May 2009 09:39:21 +0200 Christophe Grand wrote: > > Kevin Downey a écrit : > > (into {} (apply map vector > > '((cars bmw chevrolet ford peugeot) > > (genres adventure horror mystery > > > > {ford mystery, chevrolet horror, bmw adventure, cars ge

Re: constructing maps

2009-05-05 Thread Christophe Grand
Kevin Downey a écrit : > (into {} (apply map vector > '((cars bmw chevrolet ford peugeot) > (genres adventure horror mystery > > {ford mystery, chevrolet horror, bmw adventure, cars genres} > or: user=> (apply zipmap '((cars bmw chevrolet ford peugeot) (ge

Re: constructing maps

2009-05-04 Thread Kevin Downey
(into {} (apply map vector '((cars bmw chevrolet ford peugeot) (genres adventure horror mystery {ford mystery, chevrolet horror, bmw adventure, cars genres} On Mon, May 4, 2009 at 4:03 PM, Michel S. wrote: > > > > On May 4, 5:07 pm, Christophe Grand wrote

Re: constructing maps

2009-05-04 Thread Michel S.
On May 4, 5:07 pm, Christophe Grand wrote: > Michel S. a écrit : > > >> (apply conj {} (map split-kv (split-pairs test-str))) > > > The last can be simplified by using into: > > (into {} (map split-kv (split-pairs test-str))) > > It should be noted that into (and conj) is somewhat tricky with m

Re: constructing maps

2009-05-04 Thread Christophe Grand
Michel S. a écrit : >> (apply conj {} (map split-kv (split-pairs test-str))) >> >> > The last can be simplified by using into: > (into {} (map split-kv (split-pairs test-str))) > It should be noted that into (and conj) is somewhat tricky with maps: user=> (into {} '({1 2} {3 4})) {3 4, 1

Re: constructing maps

2009-05-04 Thread Michel S.
On May 4, 9:03 am, Konrad Hinsen wrote: > On May 4, 2009, at 14:23, Nathan Hawkins wrote: > > > This seems a little bit more like what I expected: > > > (map-assoc split-kv (split-pairs test-str)) > > > -> {"baz" "3", "bar" "2", "foo" "1"} > > > Am I overlooking some already existing function h

Re: constructing maps

2009-05-04 Thread Nathan Hawkins
On Mon, 04 May 2009 16:31:21 +0200 Christophe Grand wrote: > > Nathan Hawkins a écrit : > > Ok, my example seems to have misled. You're missing the point a > > little bit: > > > > 1. I was trying to avoid the (reduce conj {} ...), by having the map > > function do it. Why even build a list that

Re: constructing maps

2009-05-04 Thread Christophe Grand
Nathan Hawkins a écrit : > Ok, my example seems to have misled. You're missing the point a little > bit: > > 1. I was trying to avoid the (reduce conj {} ...), by having the map > function do it. Why even build a list that's only going to get thrown > away when I want a hash-map at the end? > > 2.

Re: constructing maps

2009-05-04 Thread Nathan Hawkins
On Mon, 4 May 2009 16:07:06 +0200 Christopher Taylor wrote: > > Hi Nathan, > > On 04.05.2009, at 15:47, Nathan Hawkins wrote: > > > > > On Mon, 4 May 2009 06:16:14 -0700 (PDT) > > Drew Raines wrote: > >> > >> Whoops, that (seq) is a debugging artifact. You can remove that: > >> > >> (let [t

Re: constructing maps

2009-05-04 Thread Drew Raines
On May 4, 8:05 am, Drew Raines wrote: > user> (let [test-str "foo=1;bar=2;baz=3"] >         (reduce conj {} >            (map #(apply hash-map (seq (.split % "="))) >                (.split test-str ";" Whoops, that (seq) is a debugging artifact. You can remove that: (let [test-str "foo=1

Re: constructing maps

2009-05-04 Thread mikel
On May 4, 7:23 am, Nathan Hawkins wrote: > Possibly I'm going about this wrong. I'm trying to understand how best > to construct maps from sequences, by applying a function which returns a > key / value pair. > > Something like this: > > (ns test (:use clojure.contrib.str-utils)) > > (def test-

Re: constructing maps

2009-05-04 Thread Christopher Taylor
Hi Nathan, On 04.05.2009, at 15:47, Nathan Hawkins wrote: > > On Mon, 4 May 2009 06:16:14 -0700 (PDT) > Drew Raines wrote: >> >> Whoops, that (seq) is a debugging artifact. You can remove that: >> >> (let [test-str "foo=1;bar=2;baz=3"] >> (reduce conj {} >> (map #(apply hash-map (.sp

Re: constructing maps

2009-05-04 Thread Nathan Hawkins
On Mon, 4 May 2009 06:16:14 -0700 (PDT) Drew Raines wrote: > > On May 4, 8:05 am, Drew Raines wrote: > > > user> (let [test-str "foo=1;bar=2;baz=3"] > >         (reduce conj {} > >            (map #(apply hash-map (seq (.split % "="))) > >                (.split test-str ";" > > Whoops,

Re: constructing maps

2009-05-04 Thread Laurent PETIT
2009/5/4 Nathan Hawkins : > > Possibly I'm going about this wrong. I'm trying to understand how best > to construct maps from sequences, by applying a function which returns a > key / value pair. > > Something like this: > > (ns test (:use clojure.contrib.str-utils)) > > (def test-str "foo=1;bar=2

Re: constructing maps

2009-05-04 Thread Drew Raines
Nathan Hawkins wrote: > Possibly I'm going about this wrong. I'm trying to understand how > best to construct maps from sequences, by applying a function which > returns a key / value pair. [...] > Am I overlooking some already existing function hidden away someplace > that does this? Here's

Re: constructing maps

2009-05-04 Thread Konrad Hinsen
On May 4, 2009, at 14:23, Nathan Hawkins wrote: > This seems a little bit more like what I expected: > > (map-assoc split-kv (split-pairs test-str)) > > -> {"baz" "3", "bar" "2", "foo" "1"} > > > Am I overlooking some already existing function hidden away someplace > that does this? Here's one w

constructing maps

2009-05-04 Thread Nathan Hawkins
Possibly I'm going about this wrong. I'm trying to understand how best to construct maps from sequences, by applying a function which returns a key / value pair. Something like this: (ns test (:use clojure.contrib.str-utils)) (def test-str "foo=1;bar=2;baz=3") (defn split-kv [text] (let [[k