Okay golfers. Is there a better way to do this?
(defn put-all!
[java-map clj-map]
(do
(doseq [entry clj-map]
(.put java-map (key entry) (val entry)))
java-map))
user=>(put-all (java.util.HashMap. ) {:a 1 :b 2 :c 3})
#<HashMap {:c=3, :b=2, :a=1}>
I already tried into :)
On Nov 17, 5:14 pm, Sean Devlin <[email protected]> wrote:
> Wow.
>
> So this works
>
> user=>(get (System/getProperties) "os.arch")
> "x86_64"
>
> And this does not
>
> user=>((System/getProperties) "os.arch")
> java.lang.ClassCastException: java.util.Properties cannot be cast to
> clojure.lang.IFn (NO_SOURCE_FILE:0)
>
> but this does
>
> user=>((into {} (System/getProperties)) "os.arch")
> "x86_64"
>
> Just when I thought I knew the API... wonder what else is out there?
> Sean
>
> On Nov 17, 5:09 pm, Richard Newman <[email protected]> wrote:
>
>
>
> > > Heh. Learn something new every day.
>
> > Heh.
>
> > Incidentally, because of this property there are only three situations
> > in which you need conversion at all:
>
> > * To get some additional interface that Clojure's maps provides (e.g.,
> > to use them as functions)
> > * To get persistence
> > * To have them print readably.
>
> > To just get values out, or walk the map, you don't need to do the
> > conversion.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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