Another way to create a map is:

user=> (apply hash-map [:a 1 :b 2 :c 3])
{:a 1, :c 3, :b 2}


On Fri, Nov 14, 2008 at 9:42 PM, samppi <[EMAIL PROTECTED]> wrote:

>
> Excellent! I must remember about the apply function. Thank you very
> much.
>
> On Nov 14, 9:35 pm, "Kevin Downey" <[EMAIL PROTECTED]> wrote:
> > On Fri, Nov 14, 2008 at 8:33 PM, Kevin Downey <[EMAIL PROTECTED]> wrote:
> > > On Fri, Nov 14, 2008 at 8:17 PM, samppi <[EMAIL PROTECTED]> wrote:
> >
> > >> Yeah, I need to be able to do this to easily manage trees of maps. I
> > >> meant, how would you idiomatically implement their algorithms?
> >
> > >> Fold isn't build into Clojure, but they should still somehow be
> > >> possible...right?
> >
> > >> On Nov 14, 9:12 pm, Michel Salim <[EMAIL PROTECTED]> wrote:
> > >>> On Nov 14, 10:56 pm, samppi <[EMAIL PROTECTED]> wrote:> I'm trying
> to figure out how to do this:
> >
> > >>> >   (flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2)
> >
> > >>> (defn flat-map-seq [m]
> > >>>   (if (empty? m) '()
> > >>>     (let [kv (first m)]
> > >>>       (lazy-cons (kv 0) (lazy-cons (kv 1) (flat-map-seq (rest
> m)))))))> ...and vice versa:
> >
> > >>> >   (map-from-flat-collection {} [:a 3 :b 1 :c 2]) ; returns {:a 3,
> :b
> > >>> > 1, :c 2}
> >
> > >>> (defn map-from-flat-collection [c]
> > >>>   (if (empty? c) {}
> > >>>     (conj (map-from-flat-collection (rrest c)) [(first c) (frest
> > >>> c)])))
> >
> > >>> > Anyone have any idiomatic ideas?
> >
> > >>> Well, not sure how idiomatic this is; apart from conj, this is how
> > >>> you'd do it in Lisp/Scheme. I'd use fold to do the first function if
> > >>> it's built into Clojure.
> >
> > >>> Regards,
> >
> > >>> --
> > >>> Michel
> >
> > > (apply assoc {} [:a 1 :b 2 :c 3])
> > > ->   {:c 3, :b 2, :a 1}
> > > --
> > > The Mafia way is that we pursue larger goals under the guise of
> > > personal relationships.
> > >    Fisheye
> >
> > user=> (apply concat (seq {:c 3, :b 2, :a 1}))
> > (:c 3 :b 2 :a 1)
> > user=>
> >
> > --
> > The Mafia way is that we pursue larger goals under the guise of
> > personal relationships.
> >     Fisheye
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to